unit ZTestToolbar;
interface
uses
SysUtils, Classes, Controls, ToolWin, ComCtrls, ImgList, cxGraphics, cxStyles,
StdCtrls, Dialogs;
type
TToolbarType = (ttStandard1, ttStandard2, ttStandard3);
type
TTestToolbar =
class(TToolBar)
private
FToolbarType: TToolbarType;
Buttons : TToolbutton;
ImageList: TcxImageList;
function GetNextName(AName:
String):
String;
procedure SetToolButtons();
procedure SetToolbarType(Value: TToolbarType);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation);
override;
public
constructor create(aOwner: TComponent);
override;
destructor Destroy;
override;
{ Private-Deklarationen }
published
property ToolbarType: TToolbarType
read FToolbarType
write SetToolbarType
default ttStandard1;
end;
procedure Register;
implementation
procedure TTestToolbar.SetToolButtons();
var
i: Integer;
begin
for i := Self.ControlCount -1
downto 0
do
Self.Controls[i].Free;
case FToolbarType
of
ttStandard1:
begin
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnEnde');
Buttons.Parent := self;
Buttons.Caption := '
Ende';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnKopieren');
Buttons.Parent := self;
Buttons.Caption := '
Kopieren';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnSichern');
Buttons.Parent := self;
Buttons.Caption := '
Sichern';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnLöschen');
Buttons.Parent := self;
Buttons.Caption := '
Löschen';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnNeu');
Buttons.Parent := self;
Buttons.Caption := '
Neu';
end;
ttStandard2:
begin
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnEnde');
Buttons.Parent := self;
Buttons.Caption := '
Ende';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextNAme('
btnLöschen');
Buttons.Parent := self;
Buttons.Caption := '
Löschen';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnVor');
Buttons.Parent := self;
Buttons.Caption := '
Vor';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnZurück');
Buttons.Parent := self;
Buttons.Caption := '
Zurück';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnSichern');
Buttons.Parent := self;
Buttons.Caption := '
Sichern';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnNeu');
Buttons.Parent := self;
Buttons.Caption := '
Neu';
end;
ttStandard3:
begin
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextNAme('
btnEnde');
Buttons.Parent := self;
Buttons.Caption := '
Ende';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnLöschen');
Buttons.Parent := self;
Buttons.Caption := '
Löschen';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnKopieren');
Buttons.Parent := self;
Buttons.Caption := '
Kopieren';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnSpeichern');
Buttons.Parent := self;
Buttons.Caption := '
Speichern';
Buttons := TToolbutton.Create(self.Parent);
Buttons.
Name := GetNextName('
btnNeu');
Buttons.Parent := self;
Buttons.Caption := '
Neu';
end;
end;
end;
procedure TTestToolbar.SetToolbarType(Value: TToolbarType);
begin
if FToolbarType <> Value
then
begin
FToolbarType := Value;
SetToolButtons();
Invalidate;
end;
end;
function TTestToolbar.GetNextName(AName:
String):
String;
var
i: Integer;
begin
i := 1;
while (Self.Owner.FindComponent(AName + IntToStr(i))) <>
nil do
i := i + 1;
Result :=(AName + IntToStr(i));
end;
constructor TTestToolbar.Create;
begin
inherited;
Parent := Owner
as TWinControl;
if Assigned(Buttons)
then
Exit;
if csDesigning
in ComponentState
then
begin
SetToolButtons();
end;
//Standardeigenschaften für Toolbar setzten
Self.ShowCaptions := True;
end;
destructor TTestToolbar.Destroy;
begin
Buttons.Free;
inherited;
end;
procedure TTestToolbar.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent = Buttons)
and (Operation = opRemove)
then
Buttons :=
nil;
end;
procedure Register;
begin
RegisterComponents('
ZTestKomponenten', [TTestToolbar]);
end;
end.