#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    86
    Rep Power
    13

    Please help - Referring to a button at runtime...


    Hi I'm busy writing a procedure that can be used across a selection of buttons but I'm not sure how to refer to the button itself via variable at runtime.

    I tried Form1('variable').caption := 'blah blah'; but of course it falls flat...

    This is a simplified example that should explain it better...

    Code:
    procedure changelabelname(Lname,Lcaption :string) 
    begin
    
    Form1.Lname.Caption := Lcaption;// Its the Lname that I would like to refer to via a variable... 
    
    end;
    
    //Calling the procedure for button 1
    
    changelablename('button1','This is button1 label');
    
    //For Button 2
    
    changelablename('button2','This is button2 label');
    Thank you in advance!

    Greg.
    Last edited by dlumley; June 4th, 2012 at 03:09 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Code:
    procedure changelabelname(aButton :TButton; Lcaption :string) 
    begin
       aButton.Caption := Lcaption;
    end;
    
    //Calling the procedure for button 1
    
    changelablename(button1,'This is button1 label');
    
    //For Button 2
    
    changelablename(button2,'This is button2 label');
    Your real issue may be more complex than this; but this should help to point the way.

    Clive
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    86
    Rep Power
    13
    Thank you!!! It is more complex but your simple piece of code adjusted my mindset in a good way!

    Greg.

IMN logo majestic logo threadwatch logo seochat tools logo