Solved

_ Getting the total number of a component.

Posted on 1998-10-31
10
178 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
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 4

Accepted Solution

by:
dwwang earned 50 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
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!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 183
Can Viruses spread while transferring Binary data with Winsock 2 98
How to debug For loops? 3 60
CheckListBox usage 3 81
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

763 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