Results 1 to 3 of 3

Thread: Question Regarding TButtons...

  1. #1
    Join Date
    Aug 2008
    Location
    Canada
    Posts
    67
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Question Question Regarding TButtons...

    I have created three TButtons using a repititions structure.

    The code look like this...
    Code:
    procedure ButtonClick(Sender: TObject);
    begin
    
    end;
    
    procedure LoadForm;
    var
      Form: TForm;
      Buttons: array of TButton;
    begin
      Form := CreateForm;
      with Form do
      begin
        Width := 500;
        Height := 300;
      end;
      SetLength(Buttons, 3);
      Captions := ['< Previous', 'Next >', 'Cancel', 'Install', 'Close'];
      for i := 0 to High(Buttons) do
      begin
        Buttons[i] := TButton.Create(Form);
        with Buttons[i] do
        begin
          Parent := Form;
          OnClick := @ButtonClick;
        end;
      end;
    I cut down the code a bunch of course...

    Now my question is, how do I tell which on of these buttons were clicked in the "ButtonClick" procedure?

    Also, what kind of information can be pull from the "Sender" Object?

    I read MasterKill's Big Form Tutorial, but I did not find a solution within it.
    He did however talk about creating TButtons using a repitition structure.

    Thank in Advance!

  2. #2
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    SCAR Code:
    procedure ButtonClick(Sender: TObject);
    begin
      case Sender of
        Buttons[0] :
          begin
          end;
        Buttons[1] :
          begin
          end;
        Buttons[2] :
          begin
          end;
        Buttons[3] :
          begin
          end;
      end;
    end;

    For components of a form you need to make them global variables.

  3. #3
    Join Date
    Aug 2008
    Location
    Canada
    Posts
    67
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Darn I was really trying to keep my variables local...

    Thanks for the information!

Thread Information

Users Browsing this Thread

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

Posting Permissions

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