Solved

Form Factory

Posted on 1998-12-26
3
346 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
ID: 1353182
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
ID: 1353183
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
ID: 1353184
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
A short film showing how OnPage and Connectwise integration works.

930 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

13 Experts available now in Live!

Get 1:1 Help Now