Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2002.01.24;
Скачать: CL | DM;

Вниз

Добавление элемента в PopUP-меню в run-time.   Найти похожие ветки 

 
Light Elf ©   (2002-01-04 20:28) [0]

Здравствуйте.
Как это реализовать? Можно просто кусок кода?

Снкс.


 
Light Elf ©   (2002-01-05 12:59) [1]

Что, никому не доводилось?


 
panov ©   (2002-01-05 13:14) [2]

var
Item: TMenuItem;
begin
Item := TMenuItem.Create(PopupMenu1);
Item.OnClick := MyProc;
Item.Caption :="Test";
PopupMenu1.Items.Add(Item);
end;


 
KSergey ©   (2002-01-05 13:39) [3]

А в чем именно проблема?
Создать it := TMenuItem.Create (...)
назначить св-ства (хотя бы заголовок и OnClick)
Добавить PopupMenu.Items.Add (it)


 
Light Elf ©   (2002-01-05 20:34) [4]

Теперь осталась одна:
назначить событию OnClick определенную процедуру.


 
panov ©   (2002-01-05 22:19) [5]

В описании формы в секции public создай свою процедуру и присвой
свойству OnClick ссылку на нее.


 
Light Elf ©   (2002-01-06 18:33) [6]

Вот ведь незадача, не получается присвоить.
В хэлпе сказано:

type

TMethod = procedure of object;
TNotifyEvent = procedure(Sender: TObject) of object;

These types represent method pointers. A method pointer is really a pair of pointers; the first stores the address of a method, and the second stores a reference to the object the method belongs to. Given the declarations

type

TNotifyEvent = procedure(Sender: TObject) of object;
TMainForm = class(TForm)
procedure ButtonClick(Sender: TObject);
...
end;
var
MainForm: TMainForm;
OnClick: TNotifyEvent

we could make the following assignment.

OnClick := MainForm.ButtonClick;

Two procedural types are compatible if they have

the same calling convention,
the same return value (or no return value), and
the same number of parameters, with identically typed parameters in corresponding positions. (Parameter names do not matter.)


Если этому последовать, то выскакивает ошибка
Incompatible Types: TNotifyEvent and "procedure, untyped pointer or untyped parameter

Так вот как это все-таки сделать? Понимаю, что просто, но как?



 
panov ©   (2002-01-06 18:46) [7]

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, StdCtrls;

type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure OnClickItem(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
Item: TMenuItem;
begin
Item := TMenuItem.Create(PopupMenu1);
Item.OnClick := OnClickItem;
Item.Caption :="Test";
PopupMenu1.Items.Add(Item);
end;

procedure TForm1.OnClickItem(Sender: TObject);
begin
ShowMessage("Ok");
end;

end.




Страницы: 1 вся ветка

Текущий архив: 2002.01.24;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.006 c
6-75630
Yuraz
2001-10-29 09:30
2002.01.24
Есть URL сайта, какой командой TCP воспользоваться, чтобы узнать чей он, на кого зарегистр. где, когда..


3-75483
Марина
2001-12-20 13:02
2002.01.24
База данных


1-75629
dima2002
2002-01-08 20:57
2002.01.24
Мастера!!! подскажите !!!


3-75520
NewComer
2001-12-19 16:46
2002.01.24
Ничего не понимю...


1-75587
Foy
2002-01-06 14:43
2002.01.24
Сохранение и вызов файла