示例代码如下(放一个Button,一个PopupMenu,一个ListBox): 请注意,我这里只建立了TMenuItem对象,你还应该在不使用的时候手工释放这些对象.procedure TForm1.Button1Click(Sender: TObject); Var I:Integer; Mit:Array of TMenuItem; begin if ListBox1.Items.Count>0 then setLength(Mit,ListBox1.Items.Count); for i:=0 to ListBox1.Items.Count-1 do begin Mit[i]:=TMenuItem.Create(PopupMenu1); Mit[i].Name:='ListBoxItem'+IntToStr(i+1); Mit[i].Caption:=ListBox1.Items[i]; PopupMenu1.Items.Add(Mit[i]); end; end;
示例代码如下(放一个Button,一个PopupMenu,一个ListBox):
请注意,我这里只建立了TMenuItem对象,你还应该在不使用的时候手工释放这些对象.procedure TForm1.Button1Click(Sender: TObject);
Var
I:Integer;
Mit:Array of TMenuItem;
begin
if ListBox1.Items.Count>0 then
setLength(Mit,ListBox1.Items.Count);
for i:=0 to ListBox1.Items.Count-1 do
begin
Mit[i]:=TMenuItem.Create(PopupMenu1);
Mit[i].Name:='ListBoxItem'+IntToStr(i+1);
Mit[i].Caption:=ListBox1.Items[i];
PopupMenu1.Items.Add(Mit[i]);
end;
end;