Solved

Form creation using names in a table

Posted on 2000-04-23
13
178 Views
Last Modified: 2010-04-04
I have the names of the forms my application uses written in a field of a table. What I need to do is find the appropiate record (based on user actions) and showmodal the corresponding form using the name written in the field. How can I do this?

Thanks A LOT in advance for your help !!
0
Comment
Question by:ajgonzalezm
[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
  • 7
  • 3
  • 3
13 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2742550
This should do it:

var
  TheFormClass : TPersistentClass;
  TheForm : TForm;

  TheFormClass := GetClass(TheTable.FieldByName('FormName').AsString);
  Application.CreateForm(TheFormClass, TheForm);
  TheForm.ShowModal;
  TheForm.Release;

Cheers,

Raymond.
0
 

Author Comment

by:ajgonzalezm
ID: 2749223
Hi, Raymond:

I didn't accept your answer just because I tried your suggestion on the computer and the compiler said: Incompatible types: ‘TComponentClass’ and ‘TPersistentClass’ on the line saying Application.CreateForm...

Could you please help me further?

THANK YOU !!!

AJ :-)
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2749422
You could use this line to create the form instead:

 TheForm := (TheFormClass as TForm).Create(Application);

Cheers,

Raymond.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ajgonzalezm
ID: 2751163
Sorry... now I got an 'Operator not applicable to this operand type' on the assigment line you suggested...

Are you willing to help me further?

Thank you :-)

AJ
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 2752995
Here's a working code sample :-)

type
  TFormClass = class of TForm;

procedure TForm1.Button1Click(Sender: TObject);
var
  TheClass : TPersistentClass;
  TheForm : TForm;
begin
  TheClass := GetClass('TFORM1');
  TheForm := TFormClass(TheClass).Create(Application);
  TheForm.ShowModal;
  TheForm.Release;
end;

Note that you need to register the classes you get GetClass to find, like this:

initialization
  registerclass(TForm1);

or

initialization
  registerclasses([TForm1, TForm2, ...]);


Cheers,

Raymond.

0
 

Author Comment

by:ajgonzalezm
ID: 2760781
THANKS A LOT RWilson !!! That was excellent !!!

I hope to become an expert like you in the near future...
by now I'm just a beginner.

Thanks again !!!

AJ
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2761075
Glad I could help - sorry about the false starts :-)

Cheers,

Raymond.
0
 

Expert Comment

by:lfgmartins
ID: 11598356
Hi,
How can I do a  registerclass(TForm1), with a the name passed from a string var ('TForm1'). I need this to alllow dynamic form names. What else I'd have to do a registerclass([TUser, TContracts,...]) form my 50 forms.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 11598501
Use the GetClass function to return the class name into a variable of type TClass and pass that to RegisterClass() as above.

Cheers,

Raymond.
0
 

Expert Comment

by:lfgmartins
ID: 11600695
unfortanelly don't work because the getclass() returns nil if the class is not registered. So I cannot apply RegisterClass next.
Thanks.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 11607307
Where are the forms coming from then?
0
 

Expert Comment

by:lfgmartins
ID: 11607960
I've found a way I first need to registerclass in initialization of that form. Then when I getclass it don't give error :)
Thanks,
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 11608596
Great!

Cheers,

Raymond.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

623 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