Solved

Dynamic Form Creation

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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