Solved

Dynamic Form Creation

Posted on 1997-05-11
2
181 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
[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 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

Independent Software Vendors: 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

628 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