Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComponentCount, Components ??? 1

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
When I ask what parent component certain components have they'll return for example a component called ChatMessages
but when I go like
Code:
var i: integer;
begin
for i := 0 to (ChatMessages.ComponentCount - 1) do
          begin
          if ChatMessages.Components[i].ClassType = TEdit then
          (ChatMessages.Components[i] as TEdit).Clear;
          if ChatMessages.Components[i].ClassType = TCheckBox then
          (ChatMessages.Components[i] as TCheckBox).Checked := False;
          end;

It won't work. So I tried this:
Code:
ShowMessage(IntToStr(ChatMessages.ComponentCount));

Which returned 0.

I'm confused by this, what am I doing wrong here? And what is the solution?


[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
what type is ChatMessages? I assume it's not a TForm. Maybe it doesn't contain any components?
 
Well, you can't know everything i guess :)

The "ChatMessages" component is a TGroupBox. Ok so it isnt a form, but it can hold child components right, so I can't figure out why that piece of code doesn't work.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
try using ControlCount to get the count of controls the groupbox own and Controls to access the control itself.
As far as I know, groupbox can contain control, not component.
Your Code will be
Code:
var i: integer;
begin
for i := 0 to (ChatMessages.ControlCount - 1) do
          begin
          if ChatMessages.Controls[i].ClassType = TEdit then
          (ChatMessages.Controls[i] as TEdit).Clear;
          if ChatMessages.Controls[i].ClassType = TCheckBox then
          (ChatMessages.Controls[i] as TCheckBox).Checked := False;
          end;
 
Thank you, indrahig!

Never even thought of that!

You just earned yourself a star :)

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top