Solved

Form Factory

Posted on 1998-12-26
3
344 Views
Last Modified: 2012-05-04
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 ?
0
Comment
Question by:qwertyuiopasdfghjkl
  • 2
3 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
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;
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
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.
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 30 total points
Comment Utility
Do this:

type
  FormClass = class of TForm;

procedure MakeAForm(var Instance : TForm; AFormClass : FormClass);

begin
  Instance := AFormClass.Create(Application);
end;

call it like this:

var
  MyForm : TMyForm;

MakeAForm(MyForm, TMyForm);

Cheers,

Raymond.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

16 Experts available now in Live!

Get 1:1 Help Now