Solved

Accessing components dynamically

Posted on 1997-05-13
2
193 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

18 Experts available now in Live!

Get 1:1 Help Now