qwertyuiopasdfghjkl
asked on
Form Factory
i would like to write a procedure that act like Form Factory that create all the form. so what type of parameter need to pass into the procedure, then the procedure will create the form ? how to do that ?
if you would like to create components on this form as well do something like below :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure myClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.myClick(Sender: TObject);
begin
with Sender as TButton do
close;
end;
procedure TForm1.Button1Click(Sender : TObject);
VAR Form2 : TForm;
b1 : TButton;
begin
Application.createform(tfo rm,form2);
b1 := TButton.Create(Self);
with b1 do begin
Left := 20;
Top := 30 ;
Width := 120;
Height := 40;
Name := 'NewButton';
Caption := 'Im a button';
OnClick := MyClick;
Parent := Form2;
end;
form2.show;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure myClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.myClick(Sender: TObject);
begin
with Sender as TButton do
close;
end;
procedure TForm1.Button1Click(Sender
VAR Form2 : TForm;
b1 : TButton;
begin
Application.createform(tfo
b1 := TButton.Create(Self);
with b1 do begin
Left := 20;
Top := 30 ;
Width := 120;
Height := 40;
Name := 'NewButton';
Caption := 'Im a button';
OnClick := MyClick;
Parent := Form2;
end;
form2.show;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i dont know what form factory is but to create a form at runtime do something like this
Regards Barry
Procedure TForm1.Button1Click(Sender
Var
Form2 :TForm;
Begin
Application.CreateForm(TFo
Form2.Show;
End;