不過,暫時先這樣吧!
底下是失敗的例子:
var actItem, actItemA: TActionClientItem; Clients: TActionClients; begin Clients := ActionMainMenuBar1.ActionClient.Items; actItemA := Clients.Add; actItemA.Caption := '&Edit'; actItem := actItemA.Items.Add; actItem.Action := EditCut1; actItem.Visible := True; actItemA.Visible := True;
正確的作法應該是:
var actItem: TActionClientItem; actRun,actRun2: TAction; begin actRun := TAction.Create(Self); actRun.Name := 'H1'; actRun.Category := 'HELLO'; actRun.OnExecute := Action1Execute; actRun2 := TAction.Create(Self); actRun2.Name := 'H2'; actRun2.Category := 'HELLO'; actRun2.OnExecute := Action1Execute; with ActionMainMenuBar1.ActionClient.Items.Add do begin Caption := 'HELLO'; Action := actRun; // 每一層一定都要掛載TAction才會把MenuItem Enable with Items.Add do begin Caption := 'HELLO2'; Action := actRun2; with Items.Add do begin Action := actRun; end; end; Visible := True; end;
Reference: Delphi Knowledge Base: Create an item in a TActionMainMenuBar at runtime
沒有留言:
張貼留言