Solved

Accessing components dynamically

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 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