just add the sender ie
SpeedButton1Click(SpeedButton1);
note if your code is not in the form class then
form1.SpeedButton1Click(form1.SpeedButton1);
personally i would move the button events outside of the form controls; that way you seperate the logic and code form the gui, and is easier to maintain.
ie
procedure mybuttonclickhandler(sender:tobject);
begin
if sender is tspeedbutton then do
begin
// code if tspeedbutton
// or a seperate procedure
end
else
if sender is tbutton then do
begin
// code if tbutton
// or a seperate procedure
end
else
if sender is tbcbutton then do
begin
// code if tbcbutton
// or a seperate procedure
end;
end;
projeect below one speedbutton one button, and the onlcik events
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Buttons, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
SpeedButton1: TSpeedButton;
procedure Button1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
procedure testa;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
// if calling from function/procedure not in tform
procedure testb;
begin
form1.SpeedButton1Click(form1.button1);
end;
// callinf from proc/function that is part of tform
procedure TForm1.testa;
begin
SpeedButton1Click(SpeedButton1);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if sender is tspeedbutton then
begin
showmessage('hello');
end
else
begin
showmessage('Ooops');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
testa; // should say hello as sending speedbutton1
testb; // should say oops as sendinf button1
end;
end.