Solved

Accessing components dynamically

Posted on 1997-05-13
2
184 Views
Last Modified: 2010-04-04
Hiya,

Is there a way in D2 to access an existing component on a form given a string that contains the name of the component?
I'm not clear that something like:
var
  cc: TPersistentClass ;
  c: TComponent;
begin
  cc := GetClass('Memo1');
  c := TComponentClass(cc).Create(application);

is appropriate because the Memo1 component was already created with the form create.  Is there a simple way.
A code snippet would be much appreciated.

Thanks,
Bob Skinner
rskinner@ix.netcom.com
component := TComponentClass(
0
Comment
Question by:skin444
2 Comments
 
LVL 2

Accepted Solution

by:
icampbe1 earned 50 total points
ID: 1336210
Every component has an entry in the forms Components array.   Loop through the array looking for the component with the same name (the name property).

For x := 0 to componentCount - 1 DO
  IF form.components[x].name = 'xxxx' THEN Break;

If you want the search by class then every object that descends from TObject (thats about all of them) can reference the ClassName property of the object instead of the Name property.

You might have to fool around with the syntax here as I haven't actually coded your solution.  ie. typecast the components array entry.

Try it and let me know.

Cheers.

0
 

Expert Comment

by:lgc5800
ID: 1336211
For access dynamically component you can see the sample from
BORLAND in the folder DEMO of DELPHI 1.2 (16bits)
The name of the .DPR is DYNAINST.DPR




0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

14 Experts available now in Live!

Get 1:1 Help Now