Solved

Use programming method create actionmanager item

Posted on 2004-04-26
5
312 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:tommyliu
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:MikProg
Comment Utility
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.
0
 
LVL 1

Author Comment

by:tommyliu
Comment Utility
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
0
 
LVL 3

Expert Comment

by:MikProg
Comment Utility
Replace ActionToolBar1 with ActionMainMenuBar1 ... voila! you have menu with absolutely same stuff.
0
 
LVL 1

Author Comment

by:tommyliu
Comment Utility
Dear MikProg,
   I cannot show any menu item could you help me more ???

thanks

Tommy
0
 
LVL 3

Accepted Solution

by:
MikProg earned 125 total points
Comment Utility
 Create new project
First
  Add ActionMainMenu1 and ActionManager1 to your form
Second
  Set ActionMainMenu1.ActionManager property to ActionManager1.
Third
  Replace ALL unit text with my piece of code
Fourth
  Set Form1.OnCreate property to my FormCreate procedure.
If you want insert some code to call into YouActionExecCodeprocedure (For example Close; closes form and exits app).

Run it. You can see MenuItem 'GetIt' press it. Place break points anywhere and explore variables
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now