Einzelnen Beitrag anzeigen

Metallicwar

Registriert seit: 5. Feb 2010
Ort: Bad Kissingen
293 Beiträge
 
Delphi XE Architect
 
#23

AW: Eigene Komponente (Toolbar) programmieren

  Alt 8. Mär 2011, 10:52
Lösung bis dahin:
Delphi-Quellcode:
unit Testtoolbar2;

interface

uses
  SysUtils, Classes, Controls, ToolWin, ComCtrls, ImgList, cxGraphics;

type TTestBars = set of (Standard1, Standard2, Standard3, Standard4, Standard5);

type
  TTestToolbar = class(TToolBar)
  public
  constructor create(aOwner: TComponent); override;
  destructor Destroy; override;
    //Bars: TTestBars;
    //Buttons: TToolButton;
    { Private-Deklarationen }
  private
    Buttons : TToolbutton;
    ImageList: TcxImageList;
    function GetNextName(AName: String): String;
  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  end;

  procedure Register;

implementation

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
    Buttons := TToolButton.Create(Parent);
    Buttons.Name := GetNextName('btnSpeichern');
    Buttons.Parent := self;
    Buttons.Caption := 'Speichern';

    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('btnVor');
    Buttons.Parent := self;
    Buttons.Caption := 'Vor';

    Buttons := TToolbutton.Create(self.Parent);
    Buttons.Name := GetNextName('btnNeu');
    Buttons.Parent := self;
    Buttons.Caption := 'Neu';
  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.
  Mit Zitat antworten Zitat