Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

_ Getting the total number of a component.

Posted on 1998-10-31
10
Medium Priority
?
182 Views
Last Modified: 2010-04-06
Suppose in a running app, I created some visual component.
(e.g. TCOMP)

how can i know how much TCOMP i have and have access to each of them?

Wein.
0
Comment
Question by:Wein
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 4

Accepted Solution

by:
dwwang earned 200 total points
ID: 1345212
You should use component arrays, when you create a component, you can assign it to a item of the array. Then you can use a counter to remember how many component you created, and use the array to access them.

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1345213
If the owner is TForm, then you can find by:
Form1.ComponentCount
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345214
Example...

var
  i : integer;
begin
  for i := 0 to ComponentCount - 1 do
    if Components[i] is TComp then
      ShowMessage(TComp(Components[i]).Name);
end;

Cheers,
Viktor
0
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!

 

Author Comment

by:Wein
ID: 1345215
How can we add things to a component array?

I need some source code
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345216
CompArray= array [0...MAX] of TCOMP;

counter:=0;
.

When you need to create:
CompArray[Counter]:=TCOMP.Create(...);
Counter:=Counter+1;
..


When you need to access:
CompArray[i].Method/property .....


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345217
var
  TCompo : array [0..5] of TComp;
  i : Integer;
{...}
for i := 0 to 5 do begin
  TCompo[i] := TComp.Create;
  TCompo[i].Width := 50;
  {...}
end;

OnDestroy()
for i := 0 to 5 do
  TCompo[i].Free;

Cheers,
Viktor
0
 

Author Comment

by:Wein
ID: 1345218
Should I give the points to dwwang or viktornet ?

He provided a clearer source. But I received the same idea from dwwang first.

I don't want to have a bad impression to any of you. So decide who wants the points. And I can also increase or decrese the points.

Wein.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345219
it doesn't make any difference to me :)
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345220
Take it easy, we won't have any bad impression for you. To answer the question is our pleasure, and score is just for interesting.

The only thing I need to see is Delphi spreading all over the world and for-ever!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345221
:)
0

Featured Post

Industry Leaders: 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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Integration Management Part 2
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

927 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