Solved

_ Getting the total number of a component.

Posted on 1998-10-31
10
173 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
Comment Utility
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
Comment Utility
If the owner is TForm, then you can find by:
Form1.ComponentCount
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
 

Author Comment

by:Wein
Comment Utility
How can we add things to a component array?

I need some source code
0
 
LVL 4

Expert Comment

by:dwwang
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
it doesn't make any difference to me :)
0
 
LVL 4

Expert Comment

by:dwwang
Comment Utility
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
Comment Utility
:)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now