我给Popupmenu1动态地添加菜单,现在要动态地响应菜单条目的Onclick事件,该如何写呢?
解决方案 »
- txt文本内容(字段名和个数可以配置文件配置)导入数据库中
- 如何在listbox中显示数据表的行???
- 双击Listview表格,如何取它的值
- ■■■ 关于写 ini文件里奇怪的问题????
- Win2000下怎样编写对硬件I/0操作的动态连接库?急!
- 用mediaplyaer开发了一个多媒体应用,客户端没有mediaplyaer的情况下怎样打包?
- 有人在Delphi中用过XML么?来谈谈使用感受。
- 通过indy的Pop3控件怎么获得一个邮箱中邮件的数量
- 单元互相传值的问题???
- 请问大家Delphi内部到底是怎样实现类型转换,有请高手回复!
- isapi 的dll在98 下可以操作注册表,为何在win2000下就不行呢?
- 请问TreeView中如何控制PopupMenu,使其只有在选择了树的结点后点右键才出现?
procedure myClick(Sender: TObject);
begin
showmessage('hellow');
end;其后popupmenu1.onclick:=myclick
PopupMenu1.Items[i].onclick := myclick;
Procedure TForm1.MyClick(MenuItemName : String);
begin
if MenuItemName = 'Item1' then
begin
do something;
end;
if MenuItemName = 'Item2' then
begin
do something;
end;
end;然后在创建tmenuitem的时候:
popumenu1.items.onclike := MyClick('Item1');ok finish
var
sqlstr:string;
t:TMenuItem;
i:integer;
with query1 do
begin
close;
sql.clear;
sqlstr:='select * from tb'+ywq+'_saleway order by swno';
sql.add(sqlstr);
open;
while not eof do
begin
t:= TMenuItem.Create(PopupMenu1);
t.Caption := fieldbyname('swname').value;
PopupMenu1.Items.Add(T);
next;
end;
end;
t:=tmenuitem.create(popupmenu1);
t.caption:='合计';
popupmenu1.items.add(t);
for i:=0 to popupmenu1.Items.Count-1 do
begin
popupmenu1.Items[i].OnClick:=myclick(i);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~这句编译不过,我不知如何声明myclick,敬请指点
end;
end;
编译无法通过,错误如下:
[Error] rbdyu.pas(349): Incompatible types: 'TNotifyEvent' and 'procedure, untyped pointer or untyped parameter'
[Fatal Error] xsbb.dpr(27): Could not compile used unit 'rbdyu.pas'
999999999999999999999999999999999999999999999999999
99999999999B@B@B@BBBMMMM999999999999999999999999999
999999999999M+:.:+9999M:999999999999999999999999999
9999999999999MM9+99MMM:9999999999999999999999999999
99999999999999M+.+99M:99999999999999999999999999999
99999999999999B:.++9M:99999999999999999999999999999
99999999999999B+.+99M:9999AAAAAA9999999999999999999
99999999999999B:.++9M:9AAA++++:+AAA9999999999999999
99999999999999B+.+99M:A+9+A:+++++9AA999999999999999
99999999999999B:.++9:A+@+A:,:++9+A9@M99999999999999
99999999999999B+.+9:A+A,,,,,,+A+A9@A@M9999999999999
99999999999999B:.++A+A+,,.,,+A9A9@A@M@M999999999999
99999999999999B+.+9AA+,,...,++A9@A@A@MM999999999999
99999999999999B:.+:A+++,,.,,++9@A@A@M@M999999999999
99999999999999B+.+A+@+,,,,,+9A@A+@@M@M@M99999999999
99999999999999B:.+A@+++,+,+9A9A++@M@M@MM99999999999
99999999999999B+.+A+@++++++A9A++9M@M@M@M99999999999
99999999999999B:.+A@+@+:+9A9A9A9M@M@M@9M99999999999
0A999999999999B+.+A+@+@+@+@+@A@A@9@9@9@M99999999999
99999999999999B:.+A@+@+@+@+@+@A@M@9@9@9M99999999999
99999999999999B+.+:A@+@+@+@+@A@M@9@9@9M999999999999
99999999999999B:.+:A9@+@+@+@9@A@M@9@9@M999999999999
99999999993333333333M9@9@9@9@9@M@9@9@9M999999999999
99999999993.........MAA99@9@9@M@9@9@9M9999999999999
99999999993...MMMM..MM@9@9@9@9@M@9@9M99999999999999
99999999993....MMM..M:M@9@9@9@9@9@9M999999999999999
99999999993...MMMM..M:9MMM@9@9@9MMM9999999999999999
99999999993..MMM.M..M:9999MMMMMM9999999999999999999
99999999993..MM.....M:99999999999999999999999999999
99999999993..M......M:99999999999999999999999999999
99999999993...M.....MM:9999999999999999999999999999
99999999993.........M9M:999999999999999999999999999
9999999999MMMMMMMMMMMMMM:99999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
99999999999999999999.9999999.9999999999999999999999
9999999....999999999.9999999.99999.999999..99999999
9999999.999.99999999.9999999.99999999999.9999999999
9999999.9999.99...99.9....99....99.9999.99999999999
9999999.9999.9.999.9.9.999.9.999.9.9999....99999999
9999999.9999.9.....9.9.999.9.999.9.9999.999.9999999
9999999.9999.9.99999.9.999.9.999.9.9999.999.9999999
9999999.999.99.999.9.9.999.9.999.9.9999.999.9999999
9999999....9999...99.9....99.999.9.99999...99999999
9999999999999999999999.9999999999999999999999999999
9999999999999999999999.9999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999
...
private
...
procedure MyClick(Sender: TObject):
...
end;procedure TForm1.MyClick(Sender: TObject);
begin
case (Sender as TMenuItem).Tag of
1://Do Something here
...
end;
end;procedure TForm1.FormShow(Sender: TObject);
var
i: Integer;
begin
for i := 0 to popupmenu1.Items.Count-1 do
popupmenu1.Items[i].OnClick:=MyClick;
end;