Solved

Form Factory

Posted on 1998-12-26
3
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 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