jixe
asked on
Retreiving toolbutton hint from OnClick procedure
I have a number of toolbars each with a number of buttons( 114 buttons altogether !). I need to find out which button has been clicked from a common OnClick procedure. I thought it should be easy enough ( and probably is if only I knew what I was doing). The toolbars have a horizontal set of buttons on each and the toolbars are stacked vertically. I can't seem to access any of the properties which might be of use eg left,top,index. My last idea was to set the hint on each button and find out that way. The hint shows OK on the form at runtime, but is blank if I do
showmessage(hint); in the onclick procedure.
This is driving me mad as I am sure you will all be shouting out the answer, but I just can't see it.
Thanks
showmessage(hint); in the onclick procedure.
This is driving me mad as I am sure you will all be shouting out the answer, but I just can't see it.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could go through and set all the tag properties of your buttons to the values ( 0 - 114)
and then assign the same OnCLick event to them
then you could look at the tag property to determine what button was pushed
ShowMessage(Inttostr( TToolButton(Sender).Tag));
case TToolButton(Sender).tag of
0: ShowMessage('Button 0 ');
1: ShowMessage('Button 1 ');
2: ShowMessage('Button 2 ');
etc.
end;
Shane
and then assign the same OnCLick event to them
then you could look at the tag property to determine what button was pushed
ShowMessage(Inttostr( TToolButton(Sender).Tag));
case TToolButton(Sender).tag of
0: ShowMessage('Button 0 ');
1: ShowMessage('Button 1 ');
2: ShowMessage('Button 2 ');
etc.
end;
Shane
Hi,
You may also use buttons names this way:
procedure TForm1.MyCommonToolButtonC lick(Sende r: TObject);
begin
if (Sender is TToolButton) then begin
with (Sender as TToolButton) do begin
if Name = 'ToolButton1' then begin
ShowMessage('ToolButton1 was pressed');
end;
if Name = 'ToolButton2' then begin
ShowMessage('ToolButton2 was pressed');
end;
// ...
end;
end;
end;
Regards, Geo
You may also use buttons names this way:
procedure TForm1.MyCommonToolButtonC
begin
if (Sender is TToolButton) then begin
with (Sender as TToolButton) do begin
if Name = 'ToolButton1' then begin
ShowMessage('ToolButton1 was pressed');
end;
if Name = 'ToolButton2' then begin
ShowMessage('ToolButton2 was pressed');
end;
// ...
end;
end;
end;
Regards, Geo
Thats alot of if thens (120 to be exact)....
how about
procedure TForm1.MyCommonToolButtonC lick(Sende r: TObject);
begin
if (Sender is TToolButton) then
with (Sender as TToolButton) do
if Name = 'ToolButton' + TToolButton(Sender).Tag then
ShowMessage('ToolButton' + IntToStr(TToolButton(Sende r).Tag ) + 'was pressed');
end;
Shane
how about
procedure TForm1.MyCommonToolButtonC
begin
if (Sender is TToolButton) then
with (Sender as TToolButton) do
if Name = 'ToolButton' + TToolButton(Sender).Tag then
ShowMessage('ToolButton' + IntToStr(TToolButton(Sende
end;
Shane
as shanes first comment:
procedure TForm1.ToolButtonClick(Sen der: TObject);
begin
if (sender is TToolButton) then
showmessage(TToolButton(se nder).Hint );
end;
procedure TForm1.ToolButtonClick(Sen
begin
if (sender is TToolButton) then
showmessage(TToolButton(se
end;
ASKER
Thanks all you guys. That was quick! Shane was first and it works ( of course).
the assign the same OnCLick event to them
ShowMessage(Inttostr( TToolButton(Sender).Tag));
Shane