我有段代码不过不是用的标准Menu控件,你看看么?包括生成菜单和调用,生成事件
标准菜单也有,调用好象就没有了,
看看吧,其中定义了一个TfrmMain的成员变量MTAuto : Array[0..100] of TMenuItem;
procedure TfrmMain.MenuMainPopup(Sender: TObject);
Var
i: Integer;
begin
for i := 0 to 100 do
if MTAuto[ i ] <> nil then
Begin
MTAuto[ i ].Free;
MTAuto[ i ] := Nil;
End
else Begin End;
dmMainADO.TSelection.Open;
dmMainADO.TSelection.First;
i := 0;
while not dmMainADO.TSelection.Eof do
Begin
MTAuto[ i ] := TMenuItem.Create( Application );
MTPope_.Insert(i,MTAuto[ i ]);
MTAuto[ i ].Visible := True;
MTAuto[ i ].Name := 'MTSelection_' + IntToStr( dmMainADO.TSelection['ID'] );
MTAuto[ i ].Caption := dmMainADO.TSelection['Name'];
MTAuto[ i ].Enabled := True;
dmMainADO.TSelection.Next;
i := i + 1;
End;
MTCount := i;
dmMainADO.TSelection.Close;
end;
procedure TfrmMain.MenuMainMenuCommand(Sender: TObject);
Var
ID : Integer;
MTName : String;
begin
With Sender as TMenuItem do
MTName := Name;
if Copy( MTName ,1,12 ) = 'MTSelection_' then
Begin
frmNBDBDataView := TfrmNBDBDataView.Create( Application );
ID := StrToInt( Copy( MTName , 13, Length(MTName) - 12 ) );
dmMainADO.QSelection.Close;
dmMainADO.QSelection.Parameters.ParamByName('ID').Value := ID;
dmMainADO.QSelection.Open;
frmNBDBDataView.Caption := dmMainADO.QSelection['Name'];
frmNBDBDataView.Title.Caption.Caption := dmMainADO.QSelection['Name'];
dmMainADO.QParams.Parameters.ParamByName('ID').Value := ID;
dmMainADO.QParams.Close;
dmMainADO.QParams.Open;
frmNBDBDataView.QDataView.Close;
frmNBDBDataView.QDataView.SQL.Clear;
frmNBDBDataView.QDataView.SQL.Add( dmMainADO.QSelection['SQLRun'] );
dmMainADO.QSelection.Close;
if frmNBDBDataView.QDataView.Parameters.Count >0 then
Begin
frmNIParams := TfrmNIParams.Create( Application );
frmNIParams.Caption := frmNBDBDataView.Caption;
frmNIParams.Title.Caption.Caption := frmNBDBDataView.Title.Caption.Caption;
frmNIParams.SQLData := frmNBDBDataView.QDataView;
frmNIParams.ParamsData := dmMainADO.QParams;
if not frmNIParams.SetParams then
Begin
dmMainADO.QParams.Close;
frmNIParams.Free;
frmNBDBDataView.Free;
Exit;
End
else Begin End;
End
else Begin End;
frmNBDBDataView.ShowModal;
frmNBDBDataView.Free;
End
end;