G'Day Folks,
In the thread "Adding buttons to TToolBar from runtime" (
https://forum.lazarus.freepascal.org/index.php/topic,57957.0.html) there was a Ttoolbar example (
https://lazarus-ccr.sourceforge.io/docs/lcl/comctrls/ttoolbar.buttons.html). In looking at the example I thought that it would be more interesting / useful if it included an onClick event handler.
I wrote some code to attempt to implement this but an getting an error. In part, my code is:
type
Tproc = procedure (sender: tobject);
TMyRec = record
cap : string;
clk : Tproc;
end;
TMyArray = array of TMyRec;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Panel1: TPanel;
ToolBar1: TToolBar;
procedure Button1Click(Sender: TObject);
private
public
procedure NewClick(Sender: TObject);
procedure SaveClick(Sender: TObject);
procedure CutClick(Sender: TObject);
procedure CopyClick(Sender: TObject);
procedure PasteClick(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
tools : TMyArray = ( (cap:'New'; clk:@NewClick),
(cap:'Save';clk:@SaveClick) );
// ^^^^^^^^ does NOT work
I am getting an error message referring to lines 38 & 39 above. The emphasis "of object" is mine.
Error: Incompatible types: got "<procedure variable type of procedure(TObject) of object;Register>" expected "<procedure variable type of procedure(TObject);Register>"
So, I think (maybe) my code is close to correct, but clearly isn't quite right!
I am attaching the lazarus project to this message.
Any suggestions would be welcomed.
cheers
S.