Link to home
Start Free TrialLog in
Avatar of Wein
Wein

asked on

_ Getting the total number of a component.

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.
ASKER CERTIFIED SOLUTION
Avatar of dwwang
dwwang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ronit051397
ronit051397

If the owner is TForm, then you can find by:
Form1.ComponentCount
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
Avatar of Wein

ASKER

How can we add things to a component array?

I need some source code
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 .....


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
Avatar of Wein

ASKER

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.
it doesn't make any difference to me :)
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!