PDA

View Full Version : Referring to everything of a certain type



Cer3brus
06-04-2009, 01:55 PM
In you were wondering how to, for example, change the caption for every label on a form...


Procedure ChangeAllLabels(Caption : String)
var
K, NumberOfLables : Integer;
Begin
NumberOfLables := 0;
For K := 0 To ComponentCount - 1 Do
Begin
If Components[K] Is TLabel
Then
Begin
TLabel(Components[K]).Caption := 'I Am TLabel';
Inc(NumberOfLables);
End;//If
End;//For
ShowMessage('There Are ' + IntToStr(NumberOfLabels) + 'Labels On Your Form';
End;//Procedure

Of course, Credit to the source: http://www.festra.com/eng/snip08.htm

ize
06-04-2009, 03:51 PM
Useful tip! 8) But just wondering why the loop doesn't start at 0 instead of 1 ???

Cer3brus
07-04-2009, 05:42 PM
Whoops!!
It IS supposed to start at 0
Sorry about that ;D

WILL
07-04-2009, 07:58 PM
Nice tip. :) Now I wonder does Lazarus have this functionality too or is this just a Delphi syntax thing?