Yo lo hago por medio de un TAction que al agregarlo en el ActionList le pongo el mismo nombre de la forma con prefijo act por ejemplo actMiForma, además en la forma al final del código le agrego
Código Delphi
[-]initialization
RegisterClass(TMiForma)
finalization
UnregisterClass(TMiForma)
Aunque esto ya lo automatice por medio de un wizard, si te interesa puedes bajar mi demás código de
http://sourceforge.net/projects/delfib
Código Delphi
[-]unit uaxActionMenu;
interface
uses
Forms, SysUtils, Classes, Controls, ActnList;
type
TaxActionMenu = class(TCustomAction)
procedure actAbrirVentanaExecute(Sender: TObject);
private
FModal: Boolean;
FOnmrOK: TNotifyEvent;
function CrearVentana(sForma: string): TForm;
procedure AbrirVentana(sForma: string);
procedure SetModal(const Value: Boolean);
procedure domrOK;
procedure SetOnmrOK(const Value: TNotifyEvent);
public
constructor Create(AOwner: TComponent); override;
function Execute: Boolean; override;
published
property Caption;
property Name;
property ShortCut;
property Modal: Boolean read FModal write SetModal default False;
property OnmrOK: TNotifyEvent read FOnmrOK write SetOnmrOK;
end;
implementation
function TaxActionMenu.CrearVentana(sForma: string): TForm;
var
FormClass: TFormClass;
begin
sForma:= StringReplace(sForma, 'act', 'frm',[]);
Result:= TForm(Application.FindComponent(sForma));
if not Assigned(Result) then
begin
FormClass:= TFormClass(GetClass('T' + sForma));
if Assigned(FormClass) then
Result:= FormClass.Create(Application);
end;
end;
procedure TaxActionMenu.AbrirVentana(sForma: string);
begin
if FModal then
begin
if CrearVentana(sForma).ShowModal = mrOK then
domrOK
end
else
CrearVentana(sForma).Show
end;
procedure TaxActionMenu.actAbrirVentanaExecute(Sender: TObject);
begin
inherited;
AbrirVentana(TAction(Sender).Name)
end;
constructor TaxActionMenu.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FModal:= False;
OnExecute:= actAbrirVentanaExecute
end;
function TaxActionMenu.Execute: Boolean;
begin
Result:= inherited Execute
end;
procedure TaxActionMenu.domrOK;
begin
if Assigned(OnmrOK) then
OnmrOK(Self)
end;
procedure TaxActionMenu.SetModal(const Value: Boolean);
begin
FModal := Value;
end;
procedure TaxActionMenu.SetOnmrOK(const Value: TNotifyEvent);
begin
FOnmrOK := Value;
end;
end.
Código Delphi
[-]unit uaxActionMenuReg;
interface
uses
SysUtils, Classes, ActnList, uaxActionMenu;
procedure Register;
implementation
procedure Register;
begin
RegisterActions('Menu', [TaxActionMenu], nil);
end;
end.