Solved

Accessing components dynamically

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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