Recent

Author Topic: How can I change a group of objects at one time??  (Read 8033 times)

wpflum

  • Sr. Member
  • ****
  • Posts: 287
How can I change a group of objects at one time??
« on: August 27, 2010, 05:15:00 pm »
Is there any way to globally change properties on groups of objects on a form?  I'm duplicating an existing program where the user can change the color of the font, screen and entry boxes so I'd like to be able to run a procedure that will change the colors for groups of TEDIT boxes and TLABLES at one time.  Can I group these together some how to do them all at once or is there some way to loop through all the TEDITS on a form so I can do it that way.


Bill

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How can I change a group of objects at one time??
« Reply #1 on: August 27, 2010, 05:17:17 pm »
You need to loop through the controls.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12108
  • Debugger - SynEdit - and more
    • wiki
Re: How can I change a group of objects at one time??
« Reply #2 on: August 27, 2010, 05:19:12 pm »
There is ParentFont which is true.
So if you have 10 labels in a panel, and you change the color of the panels font => bingo


Otherwise
Tform.Controls



wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: How can I change a group of objects at one time??
« Reply #3 on: August 27, 2010, 05:31:56 pm »
You need to loop through the controls.

That's what I thought but I don't know how.


wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: How can I change a group of objects at one time??
« Reply #4 on: August 27, 2010, 05:33:37 pm »
There is ParentFont which is true.
So if you have 10 labels in a panel, and you change the color of the panels font => bingo


Otherwise
Tform.Controls
I don't want to change all of the controls to the same color so that wont work.  I'll look at the Tform.Controls
  • to see if I can figure that out.


Thanks

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How can I change a group of objects at one time??
« Reply #5 on: August 27, 2010, 05:37:24 pm »
Well, you can namely change the desired property of each one or:

Code: [Select]
for i := 0 to ControlCount - 1 do
begin
  if Controls[i] is TLabel then DoSomething;
end;
« Last Edit: August 27, 2010, 05:42:03 pm by typo »

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: How can I change a group of objects at one time??
« Reply #6 on: August 27, 2010, 05:41:00 pm »
Ok, I can get to the controls using the TForm.Controls,  now how can I tell if the control is a TEDIT or TLABEL?? 

On a side note is there anywhere I can reference stuff like this so in the future I can read up on what a property does instead of just typing in the form name then a '.' to see the drop down of options that I have to then scroll through and hope I spot what I need??


BlueIcaro

  • Hero Member
  • *****
  • Posts: 832
    • Blog personal
Re: How can I change a group of objects at one time??
« Reply #7 on: August 27, 2010, 05:44:10 pm »
This code shows how to change Caption property of a TLabel called Label2, of course you can change/access to other properties os the labels.
Quote
procedure TForm1.Button1Click (Sender: TObject );
var
  I: Integer;
  MyLabel: TControl;

begin
  For I:= 0 To Form1.ControlCount-1 Do
  Begin
      If Form1.Controls is TLabel Then
      Begin
         MyLabel := Form1.Controls;
         If MyLabel.Name = 'Label2' Then
         Begin
            MyLAbel.Caption:='Hola';
         end;
      end;
  end;
end;                 

/BlueIcaro

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: How can I change a group of objects at one time??
« Reply #8 on: August 27, 2010, 05:46:16 pm »
Well, you can namely change the desired property of each one or:

Code: [Select]
for i := 0 to ControlCount - 1 do
begin
  if Controls[i] is TLabel then DoSomething;
end;

I tried this but I'm getting  an error saying the identifier TLable is not found, am I missing something in my uses clause?

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: How can I change a group of objects at one time??
« Reply #9 on: August 27, 2010, 05:50:10 pm »
Doh..... helps if I spell TLABEL correctly instead of TLable.........


BlueIcaro

  • Hero Member
  • *****
  • Posts: 832
    • Blog personal
Re: How can I change a group of objects at one time??
« Reply #10 on: August 27, 2010, 05:51:49 pm »
Do you have StdCtrls in you uses clause?

/blueIcaro

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: How can I change a group of objects at one time??
« Reply #11 on: August 27, 2010, 05:55:26 pm »
Yea that's there.  I just spelled TLabel wrong  :-[

Now it's working and I can blunder on to the next impasse.  ;)

Thanks all.


 

TinyPortal © 2005-2018