Solved

Form Factory

Posted on 1998-12-26
3
348 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Making delphi communicate with a c# service 16 103
LAN or WAN ? 11 91
Delphi inherited method 6 70
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 34
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

772 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