Results 1 to 4 of 4

Thread: Referring to everything of a certain type

  1. #1

    Referring to everything of a certain type

    In you were wondering how to, for example, change the caption for every label on a form...

    Code:
    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

  2. #2

    Re: Referring to everything of a certain type

    Useful tip! But just wondering why the loop doesn't start at 0 instead of 1
    Windows Vista x64 Ultimate<br />AMD Athlon x64 4000+<br />Codegear Delphi 2009, Delphi 2007, Borland Delphi 7

  3. #3

    Re: Referring to everything of a certain type

    Whoops!!
    It IS supposed to start at 0
    Sorry about that

  4. #4
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: Referring to everything of a certain type

    Nice tip. Now I wonder does Lazarus have this functionality too or is this just a Delphi syntax thing?
    Jason McMillen
    Pascal Game Development
    Co-Founder





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •