How to count components ?

I have an MDI-Application.
On one of the Child-Forms there are 2 frames. On each frame there are dbedit-components.
I want to write a procedure who sets the enabled and the color-property
of all the dbedit-components who are situated on one of the 2 frames.
HOW CAN I DO THIS ?

Thanks in advance ...
LVL 6
wimmeyvaertAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rcastleCommented:
set tag on all dbedits to 1 then use this code to enable all dbedits.  I'll leave color as an exercise. <grin>

    for i := 1 to Form1.ComponentCount do
      if Form1.Components[i-1].Tag = 1 then
        (Form1.Components[i-1] as DBEdit).Enabled := true;
0
wimmeyvaertAuthor Commented:
I don't think this will solve my problem (because I have to set the tag-property for each dbedit at design-time).

What I'm looking for is a way to count the components who were placed on another component (a panel) at design-time.
For the moment my code look like this :
for intx:=0 to Panel1.ComponentCount-1 do
  ShowMessage(Panel1.Components[intx].Name);

But Panel1.ComponentCount is always 0, the for-loop is never started.

Isn't there a way to count the components who are on for instance a panel, or do I have to use another component?
0
huizhangCommented:
hi wimmeyveaert,

If you are using dbEdit control, you can try to use ControlCount
instead of ComponentCount.

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin   showmessage('panel1.componentcount='+inttostr(panel1.controlcount));
  for i:=0 to Panel1.ControlCount-1 do
    if Panel1.Controls[i] is TdbEdit then
      showmessage('tdbEdit is found!');
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

sburckCommented:
You can use ComponentCount on the form containing the panel, and check the parentage of each component - if it's on the panel, the panel will be it's parent.

This is Delphi 4, and I don't know if it'll be true for frames in Delphi 5.  Borland is having a chat on Frames tonight, though, you could try asking there.
0
kretzschmarCommented:
hi wimmeyvaert,

use controlcount instead of
componentcount as  huizhang mentioned

meikl
0
wimmeyvaertAuthor Commented:
thanks,
Up to the following problem !!!

CU :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.