unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,StdCtrls, ExtCtrls, ComCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
ToolBar1: TToolBar;
procedure Button1Click(Sender: TObject);
private
public
procedure DoBUttons(Sender:Tobject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
Procedure TForm1.DoButtons(Sender:TObject);
Begin
Case TtoolButton(Sender).Tag Of
0:Caption := 'Copy'; //{Do Copy};
1:Caption := 'Paste';//{Do Paste};
end;
end;
Procedure AddMeToButtons(AToolbar:TToolBar; AClickEvent:TNotifyEvent; AButtons:Array of String);
Var
I :Integer;
Begin
for i := 0 to High(AButtons) do
begin
with TToolButton.Create(AToolBar) do
begin
Parent := AToolBar;
Caption := AButtons[i];
if (Abuttons[i] = '|') then
Style := tbsSeparator
else
begin
Style := tbsButton;
onclick := AClickEvent;
end;
AutoSize := True;
Visible := true;
left := parent.width;
Tag := I;// Array Index;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AddMeToButtons(ToolBar1, @doButtons,['Copy','Paste']);
end;
end.