先定义一个: MenuItem : array of TMenuItem; //动态菜单
//创建动态菜单组
procedure TfrmMain.CreateMenuItem(Sender: TObject);
var
i: integer;
begin
SetLength(MenuItem, LVFileList.Items.Count); //分配长度
for i := 0 to Length(MenuItem) -1 do
Begin
MenuItem := TMenuItem.Create(nil);
with MenuItem do
begin
CmdSysName.Add(MenuItem);
MenuItem.Name := 'Item' + inttostr(i);
caption := LVFileList.Items.Item.Caption;
hint := LVFileList.Items.Item.SubItems[4];
OnClick := MenuItemClick;
MenuItem.ImageIndex := LVFileList.Items.Item.ImageIndex;
end;
end;
end;