Solved

_ Getting the total number of a component.

Posted on 1998-10-31
10
176 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 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TVirtualStringTree  search using TEdit 7 121
Open a URL with Internet Explorer in a new tab (not a new window) 1 99
LAN or WAN ? 11 92
RESTRequest Parameter 4 31
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…

831 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