问题如下:
把数据库里的数据用来动态生成菜单项,但是我不知道怎样判断我单击了哪个菜单项,所有的单击事件都指向了N1Click过程,因为我不知道会随数据库的数据产生多少菜单项。
procedure TDBXP_RKD.edt_spmcClick(Sender: TObject);
var
i_spmc,count_spmc:integer;
begin
with dm_dbxp.qry_spmc do begin
close;
sql.Clear;
sql.Add('select * from dbxp_sp');
open;
end;
count_spmc:=dm_dbxp.qry_spmc.RecordCount;
for i_spmc := 1 to count_spmc do
begin
NewItem := TMenuItem.Create(PopupMenu1);
NewItem.Caption := dm_dbxp.qry_spmc.FieldByName('spmc_no').AsString;
PopupMenu1.Items.Add( NewItem);
newitem.OnClick := N1Click;
dm_dbxp.qry_spmc.Next;
end;
PopupMenu1.Popup(x,y);
end;
procedure TDBXP_RKD.N1Click(Sender: TObject);
begin
怎样在这里判断我单击了哪个菜单项?
popupmenu1.Items.Clear;
end;
小弟技穷请各位大虾帮忙!
-----------------------------------------------------------------------------------------------------------------------------------
1.
太简单了,
procedure TDBXP_RKD.N1Click(Sender: TObject);
begin
//怎样在这里判断我单击了哪个菜单项?
with TMenuItem(Sender) do
begin
ShowMessage('你点击了"'+Caption+'"!');
end;
end;
2.
根据sender啊
procedure TDBXP_RKD.N1Click(Sender: TObject);
var
name :string;
begin
name :=TMenuItem(Sender).name;//菜单名称
popupmenu1.Items.Clear;
end;
3.
ype
TFunctionProc=function:boolean;
procedure TMainForm.SystemFunctionClick(Sender: TObject);//系统菜单事件
var
AHandle : THandle;
BaseInfoProc : TFunctionProc;
FunProc:string;
begin
if Sender is TMenuItem then
begin
FunProc:=(Sender as TMenuItem).KeyValue;
AHandle := GetModuleHandle(Nil);
if AHandle <> 0 then
begin
@BaseInfoProc := GetProcAddress(AHandle,PChar(FunProc));
if @BaseInfoProc <> nil then
begin
Update;
BaseInfoProc;
end;
end;
end;
end;
把数据库里的数据用来动态生成菜单项,但是我不知道怎样判断我单击了哪个菜单项,所有的单击事件都指向了N1Click过程,因为我不知道会随数据库的数据产生多少菜单项。
procedure TDBXP_RKD.edt_spmcClick(Sender: TObject);
var
i_spmc,count_spmc:integer;
begin
with dm_dbxp.qry_spmc do begin
close;
sql.Clear;
sql.Add('select * from dbxp_sp');
open;
end;
count_spmc:=dm_dbxp.qry_spmc.RecordCount;
for i_spmc := 1 to count_spmc do
begin
NewItem := TMenuItem.Create(PopupMenu1);
NewItem.Caption := dm_dbxp.qry_spmc.FieldByName('spmc_no').AsString;
PopupMenu1.Items.Add( NewItem);
newitem.OnClick := N1Click;
dm_dbxp.qry_spmc.Next;
end;
PopupMenu1.Popup(x,y);
end;
procedure TDBXP_RKD.N1Click(Sender: TObject);
begin
怎样在这里判断我单击了哪个菜单项?
popupmenu1.Items.Clear;
end;
小弟技穷请各位大虾帮忙!
-----------------------------------------------------------------------------------------------------------------------------------
1.
太简单了,
procedure TDBXP_RKD.N1Click(Sender: TObject);
begin
//怎样在这里判断我单击了哪个菜单项?
with TMenuItem(Sender) do
begin
ShowMessage('你点击了"'+Caption+'"!');
end;
end;
2.
根据sender啊
procedure TDBXP_RKD.N1Click(Sender: TObject);
var
name :string;
begin
name :=TMenuItem(Sender).name;//菜单名称
popupmenu1.Items.Clear;
end;
3.
ype
TFunctionProc=function:boolean;
procedure TMainForm.SystemFunctionClick(Sender: TObject);//系统菜单事件
var
AHandle : THandle;
BaseInfoProc : TFunctionProc;
FunProc:string;
begin
if Sender is TMenuItem then
begin
FunProc:=(Sender as TMenuItem).KeyValue;
AHandle := GetModuleHandle(Nil);
if AHandle <> 0 then
begin
@BaseInfoProc := GetProcAddress(AHandle,PChar(FunProc));
if @BaseInfoProc <> nil then
begin
Update;
BaseInfoProc;
end;
end;
end;
end;