Link to home
Start Free TrialLog in
Avatar of qwertyuiopasdfghjkl
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 ?
Avatar of inthe
inthe

hi
i dont know what form factory is but to create a form at runtime do something like this
Regards Barry

Procedure TForm1.Button1Click(Sender : TObject);
Var
 Form2 :TForm;
Begin
Application.CreateForm(TForm,Form2);
Form2.Show;
End;
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(tform,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.
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

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