Solved

Dynamic Form Creation

Posted on 1997-05-11
2
177 Views
Last Modified: 2010-05-18
Hiya,

Is it possible to instantiate objects (specifically a TForm) dynamically
at run-time from a String with value := to the name of a specific form?
I'm assuming it's not possible to store the Form object itself in a
Paradox table but I could store the name of the Form as a string, no?

Any little code snippet would be appreciated.

Thanks,
 Bob Skinner

rskinner@ix.netcom.com
0
Comment
Question by:skin444
2 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1336127
It is possible to create a form based on the name of the class.

Form1 is of class TForm1
FormMain is of class TForm2

This requires you to add code to register the forms in the initialization section of the units. The following code works under Delphi 3, I'm not sure whether D2 will accept it.

----------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  fc      : TPersistentClass;
  f       : TForm;
begin
  fc := GetClass('TForm2');
  if fc <> nil then begin
    f :=  TFormClass(fc).Create(Application);
    f.Show;
  end;
end;

initialization
  RegisterClass (TForm1);
end.
------------------------------------
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

initialization
  RegisterClass (TForm2);
end.
-----------------------



0
 

Author Comment

by:skin444
ID: 1336128

Thanks sperling!

It does work under D2.  Code sample was just what I was looking for.

-Bob
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
calling Tcolordialog in dll make the form disappear 8 111
Best Firemonkey component pack 1 103
select query - oracle 16 100
TServerSocket - file via sendbuf or Text via sendtext ? 1 53
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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