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
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.
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
The problem is they don't do they same job, they do similar jobs.
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
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.
Ok thanks![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks