Closed Thread
Results 1 to 7 of 7

Thread: Linking several buttons to one procedure

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Linking several buttons to one procedure

    Hi again

    I have a button that executes this procedure on click:

    procedure TTillform.Button7Click(Sender: TObject);
    begin
    display.Text:= display.Text + '7';
    end;

    I have about 8 more other buttons which have the exact same procedure but just different numbers. So I've written the procedures for each button. I was just wondering that there must be a better way ie:

    for count:= 0 to 9
    do
    begin

    procedure TTillform.Button(count)Click(Sender: TObject);
    begin
    display.Text:=display.text + (Count);
    end;

    But Im pretty sure this won't work since it is calling the procedure therefore skipping the count code.

    Thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Linking several buttons to one procedure

    Short of checking which button object Sender is, not really. I'm not sure what you want to do will be shorter than several methods.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Linking several buttons to one procedure

    Well, considering all nine buttons do the same job, I thought it would be easier to bunch them into one procedure.

    Basically I have a sort of number pad, numbered 0-9. Each time I press one, it displays that number in the text box, and its kinda tedious to have to do it for all 9, but if there isn't a way, then I guess it'll have to do. Just that in the future, there may be like 100s of buttons on a form which do the same thing, so I just thought they must be a way.

    Thanks

  5. #4
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Linking several buttons to one procedure

    The problem is they don't do they same job, they do similar jobs.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Linking several buttons to one procedure

    would it be possible if they did do the same job? What would I have to do to get more than one button to 1 procedure?

    Thanks

  7. #6
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Linking several buttons to one procedure

    On the events tab of the object inspector, select the procedure for the button click.

    You can also add conditional logic to the procedure to have it test which button is the sender, if needed.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  8. #7
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Linking several buttons to one procedure

    Ok thanks

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Procedure Marshalling
    By Apprentice123 in forum Programming Theory
    Replies: 0
    Last Post: 08-16-2011, 04:16 PM
  2. MASM Procedure help
    By Slider in forum Assembly
    Replies: 4
    Last Post: 01-29-2011, 04:55 PM
  3. Bug in ESC procedure
    By Actor in forum Pascal and Delphi
    Replies: 9
    Last Post: 06-06-2010, 02:00 PM
  4. Upgrade Procedure
    By tony4x4 in forum ionFiles
    Replies: 1
    Last Post: 01-05-2009, 06:02 AM
  5. and procedure problem
    By jamesw in forum Programming Theory
    Replies: 3
    Last Post: 10-20-2008, 08:56 AM

Tags for this Thread

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