Link to home
Start Free TrialLog in
Avatar of tommyliu
tommyliuFlag for Hong Kong

asked on

Use programming method create actionmanager item

Dear experts,

   I have a question about actionmanager. I want to use programming method the create actionmanager->action bar-> item. Is it possible to do it? If you can, would you give me a sample for it. Thanks alot.

Tommy
Avatar of MikProg
MikProg

Here it is. It is smple. Add ActionBars,  ActionItems and never forget to RecreateControls to update ToolBar image.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, XPStyleActnCtrls, ActnList, ActnMan, ToolWin, ActnCtrls;

type
  TForm1 = class(TForm)
    ActionManager1: TActionManager;
    ActionToolBar1: TActionToolBar;
    procedure FormCreate(Sender: TObject);
    procedure YouActionExecCodeprocedure (Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  with ActionManager1.ActionBars.Add do
  begin
    ActionBar:=ActionToolBar1;
    with Items.Add do
    begin
     Action:=TAction.Create(ActionManager1);
     with Action do
     begin
       Caption:='Get It!';
       Visible:=True;
       OnExecute:=YouActionExecCodeprocedure;
     end;
    end;
  end;
  ActionToolBar1.RecreateControls;
end;

procedure TForm1.YouActionExecCodeprocedure(Sender: TObject);
begin
//
end;

end.
Avatar of tommyliu

ASKER

Dear MikProg,
   I think you answer is very near, but could you give me more hints because I am a newbie. Actually I want to create a ActionMainMenuBar. Thanks for you help !

Tommy
Replace ActionToolBar1 with ActionMainMenuBar1 ... voila! you have menu with absolutely same stuff.
Dear MikProg,
   I cannot show any menu item could you help me more ???

thanks

Tommy
ASKER CERTIFIED SOLUTION
Avatar of MikProg
MikProg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial