Bir ToolBar bileseni hazirlamaya calisiyorum fakat create etmis oldugum butonlardan birinin OnClick özelligini projemin icinde kullanmak istedigimde calismiyor. Bu konuda oldukca yeniyim, ilk bilesenim. Tecrübesizligim bu yüzden.
Kolar asagida görüldügü gibi...
Kod: Tümünü seç
unit EGAdvDockPanel;
interface
uses
Windows, Classes, Controls, Graphics, Messages, Types, Forms, Dialogs,
Math, SysUtils, ExtCtrls, ComCtrls, Buttons,
AdvToolBar, AdvToolBarStylers, AdvFontCombo, cxRichEdit, AdvSelectors,
RzPanel, AdvToolBtn;
type
TBarButton = Class;
TBarButton = class(TAdvToolBarButton)
private
protected
public
constructor Create(AOwner: TComponent); override;
published
property OnClick;
end;
TEGAdvDockPanel = class(TAdvDockPanel)
private
{ Private declarations }
FToolBarStyler : TAdvToolBarOfficeStyler;
FImage : TImageList;
FRich : TcxCustomRichEdit;
FToolBar : TAdvToolBar;
FBtnCut : TAdvToolBarButton;
FBtnCopy : TAdvToolBarButton;
FBtnPaste : TAdvToolBarButton;
FBtnUndo : TAdvToolBarButton;
FPanel : TRzPanel;
FFontSelector : TAdvFontSelector;
FSpinEdit : TAdvOfficeComboBox;
FColorSelector : TAdvTextColorSelector;
FBtnBold : TAdvToolBarButton;
FBtnItalic : TAdvToolBarButton;
FBtnUnderline : TAdvToolBarButton;
FSeperator1 : TAdvToolBarSeparator;
FBtnLeftAlign : TAdvToolBarButton;
FBtnCenterAlign : TAdvToolBarButton;
FBtnRightAlign : TAdvToolBarButton;
FSeperator2 : TAdvToolBarSeparator;
FBtnPrint : TBarButton;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure SetImage(const Value : TImageList);
procedure BtnClick(Sender : TObject);
procedure CmbChange(Sender : TObject);
procedure ColorSelect(Sender: TObject; Index: Integer; Item: TAdvSelectorItem);
procedure SetRich(const Value : TcxCustomRichEdit);
procedure RichSelectionChange(Sender : TObject);
published
{ Published declarations }
property IconList : TImageList read FImage write SetImage;
property Rich : TcxCustomRichEdit read FRich write SetRich;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('eigene', [TEGAdvDockPanel]);
end;
//-------------------------------------------------------------------------
constructor TBarButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
//-------------------------------------------------------------------------
constructor TEGAdvDockPanel.Create(AOwner : TComponent);
var i : integer;
begin
inherited Create(AOwner);
{Styler}
if not Assigned(FToolBarStyler) then
FToolBarStyler := TAdvToolBarOfficeStyler.Create(self);
FToolBarStyler.Style := bsOffice2003Blue;
ToolBarStyler := FToolBarStyler;
{Toolbar}
if not Assigned(FToolBar) then
FToolBar := TAdvToolBar.Create(self);
with FToolBar do
begin
ShowOptionIndicator := false;
ToolBarStyler := FToolBarStyler;
AllowFloating := false;
Locked := true;
Parent := self;
if Assigned(FImage) then images := FImage;
Show;
end;
if not Assigned(FBtnCut) then
FBtnCut := TAdvToolBarButton.Create(AOwner);
with FBtnCut do
begin
Name := 'Cut';
Hint := 'Ausschneiden';
Tag := 0;
ImageIndex := 0;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnCut);
if not Assigned(FBtnCopy) then
FBtnCopy := TAdvToolBarButton.Create(AOwner);
with FBtnCopy do
begin
Name := 'Copy';
Hint := 'Kopieren';
Tag := 1;
ImageIndex := 1;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnCopy);
if not Assigned(FBtnPaste) then
FBtnPaste := TAdvToolBarButton.Create(AOwner);
with FBtnPaste do
begin
Name := 'Paste';
Hint := 'Einfügen';
Tag := 2;
ImageIndex := 2;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnPaste);
if not Assigned(FBtnUndo) then
FBtnUndo := TAdvToolBarButton.Create(AOwner);
with FBtnUndo do
begin
Name := 'Undo';
Hint := 'Zurück';
Tag := 3;
ImageIndex := 3;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnUndo);
if not Assigned(FPanel) then
FPanel := TRzPanel.Create(self);
with FPanel do
begin
Name := 'FPanel';
width := 237;
height := 23;
BorderSides := [];
Transparent := true;
end;
FToolBar.AddToolBarControl(FPanel);
if not Assigned(FFontSelector) then
FFontSelector := TAdvFontSelector.Create(AOwner);
with FFontSelector do
begin
Name := 'FontSelect';
Style := csDropDownList;
DisplayRecentSelection := false;
Top := 3;
Left := 3;
width := 150;
Tag := 0;
OnChange := CmbChange;
Parent := FPanel;
end;
if not Assigned(FSpinEdit) then
FSpinEdit := TAdvOfficeComboBox.Create(AOwner);
with FSpinEdit do
begin
Name := 'Spin';
Top := 3;
Left := 156;
Width := 40;
Tag := 1;
Style := csDropDownList;
DisplayRecentSelection := false;
i := 8;
while i < 32 do
begin
Items.Add(IntToStr(i));
i := i + 1;
if i > 10 then i := i + 1;
end;
OnChange := CmbChange;
Parent := FPanel;
end;
if not Assigned(FColorSelector) then
FColorSelector := TAdvTextColorSelector.Create(AOwner);
with FColorSelector do
begin
Name := 'ColorSelect';
Style := ssCombo;
Top := 3;
Left := 199;
width := 35;
Height := 19;
AppearanceStyle := esOffice2003Blue;
OnSelect := ColorSelect;
Parent := FPanel;
end;
if not Assigned(FBtnBold) then
FBtnBold := TAdvToolBarButton.Create(AOwner);
with FBtnBold do
begin
Name := 'Bold';
Hint := 'Fett';
Tag := 4;
ImageIndex := 4;
//Style := tasCheck;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnBold);
if not Assigned(FBtnItalic) then
FBtnItalic := TAdvToolBarButton.Create(AOwner);
with FBtnItalic do
begin
Name := 'Italic';
Hint := 'Kursiv';
Tag := 5;
ImageIndex := 5;
//Style := tasCheck;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnItalic);
if not Assigned(FBtnUnderline) then
FBtnUnderline := TAdvToolBarButton.Create(AOwner);
with FBtnUnderline do
begin
Name := 'Underline';
Hint := 'Unterstrichen';
Tag := 6;
ImageIndex := 6;
//Style := tasCheck;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnUnderline);
if not Assigned(FSeperator1) then
FSeperator1 := TAdvToolBarSeparator.Create(self);
with FSeperator1 do
begin
LineColor := clBlack;
AdvToolBar := FToolBar;
end;
if not Assigned(FBtnLeftAlign) then
FBtnLeftAlign := TAdvToolBarButton.Create(AOwner);
with FBtnLeftAlign do
begin
Name := 'LeftAlign';
Hint := 'Linksbündig';
Tag := 7;
ImageIndex := 7;
GroupIndex := 1;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnLeftAlign);
if not Assigned(FBtnCenterAlign) then
FBtnCenterAlign := TAdvToolBarButton.Create(AOwner);
with FBtnCenterAlign do
begin
Name := 'CenterAlign';
Hint := 'Zentriert';
Tag := 8;
ImageIndex := 8;
GroupIndex := 1;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnCenterAlign);
if not Assigned(FBtnRightAlign) then
FBtnRightAlign := TAdvToolBarButton.Create(AOwner);
with FBtnRightAlign do
begin
Name := 'RightAlign';
Hint := 'Rechtsbündig';
Tag := 9;
ImageIndex := 9;
GroupIndex := 1;
OnClick := BtnClick;
end;
FToolBar.AddToolBarControl(FBtnRightAlign);
if not Assigned(FSeperator2) then
FSeperator2 := TAdvToolBarSeparator.Create(self);
with FSeperator2 do
begin
LineColor := clBlack;
AdvToolBar := FToolBar;
end;
if not Assigned(FBtnPrint) then
FBtnPrint := TBarButton.Create(AOwner);
with FBtnPrint do
begin
Name := 'Drucken';
Hint := 'Drucken';
//Tag := 10;
//ImageIndex := 10;
end;
FToolBar.AddToolBarControl(FBtnPrint);
end;
//------------------------------------------------------------------------------
destructor TEGAdvDockPanel.Destroy;
begin
if Assigned(FToolBarStyler) then FToolBarStyler.Free;
if Assigned(FFontSelector) then FFontSelector.Free;
if Assigned(FSpinEdit) then FSpinEdit.Free;
if Assigned(FColorSelector) then FColorSelector.Free;
if Assigned(FSeperator1) then FSeperator1.Free;
if Assigned(FSeperator2) then FSeperator2.Free;
if Assigned(FBtnCut) then FBtnCut.Free;
if Assigned(FBtnCopy) then FBtnCopy.Free;
if Assigned(FBtnPaste) then FBtnPaste.Free;
if Assigned(FBtnUndo) then FBtnUndo.Free;
if Assigned(FBtnBold) then FBtnBold.Free;
if Assigned(FBtnItalic) then FBtnItalic.Free;
if Assigned(FBtnUnderline) then FBtnUnderline.Free;
if Assigned(FBtnLeftAlign) then FBtnLeftAlign.Free;
if Assigned(FBtnCenterAlign) then FBtnCenterAlign.Free;
if Assigned(FBtnRightAlign) then FBtnRightAlign.Free;
if Assigned(FBtnPrint) then FBtnPrint.Free;
if Assigned(FPanel) then FPanel.Free;
if Assigned(FToolBar) then FToolBar.Free;
inherited;
end;
//------------------------------------------------------------------------------
procedure TEGAdvDockPanel.SetRich(const Value : TcxCustomRichEdit);
begin
if FRich <> Value then FRich := Value;
with FRich, Properties, Style do
begin
OnSelectionChange := RichSelectionChange;
Font.Name := 'Tahoma';
HideSelection := false;
SelectionBar := true;
end;
with FFontSelector do
ItemIndex := Items.IndexOf(FRich.Style.Font.Name);
end;
//------------------------------------------------------------------------------
procedure TEGAdvDockPanel.SetImage(const Value : TImageList);
begin
if FImage <> Value then FImage := Value;
FToolBar.Images := FImage;
end;
//------------------------------------------------------------------------------
procedure TEGAdvDockPanel.RichSelectionChange(Sender : TObject);
begin
if Assigned(FRich) then
begin
FBtnBold.Down := fsBold in FRich.SelAttributes.Style;
FBtnItalic.Down := fsItalic in FRich.SelAttributes.Style;
FBtnUnderline.Down := fsUnderline in FRich.SelAttributes.Style;
FBtnCut.Enabled := FRich.SelLength > 0;
FBtnCopy.Enabled := FBtnCut.Enabled;
// select current font and color
FColorSelector.SelectedColor := FRich.SelAttributes.Color;
FFontSelector.ItemIndex := FFontSelector.Items.IndexOf(FRich.SelAttributes.Name);
FSpinEdit.ItemIndex := FSpinEdit.Items.IndexOf(IntToStr(FRich.SelAttributes.Size));
case Ord(FRich.Paragraph.Alignment) of
0: FBtnLeftAlign.Down := True;
1: FBtnRightAlign.Down := True;
2: FBtnCenterAlign.Down := True;
end;
end;
end;
//------------------------------------------------------------------------------
procedure TEGAdvDockPanel.BtnClick(Sender : TObject);
begin
if Assigned(FRich) then
begin
case TComponent(Sender).Tag of
0 : FRich.CutToClipboard;
1 : FRich.CopyToClipboard;
2 : FRich.PasteFromClipboard;
3 : FRich.Undo;
4 : with FRich.SelAttributes do
if fsBold in Style then Style := Style - [fsBold]
else Style := Style + [fsBold];
5 : with FRich.SelAttributes do
if fsItalic in Style then Style := Style - [fsItalic]
else Style := Style + [fsItalic];
6 : with FRich.SelAttributes do
if fsUnderline in Style then Style := Style - [fsUnderline]
else Style := Style + [fsUnderline];
7 : FRich.Paragraph.Alignment := TAlignment(taLeftJustify);
8 : FRich.Paragraph.Alignment := TAlignment(taCenter);
9 : FRich.Paragraph.Alignment := TAlignment(taRightJustify);
end;
end;
end;
//------------------------------------------------------------------------------
procedure TEGAdvDockPanel.CmbChange(Sender : TObject);
begin
if Assigned(FRich) then
case TComponent(Sender).Tag of
0 : FRich.SelAttributes.Name := FFontSelector.Text;
1 : FRich.SelAttributes.Size := StrToInt(FSpinEdit.Text);
end;
end;
//------------------------------------------------------------------------------
procedure TEGAdvDockPanel.ColorSelect(Sender: TObject; Index: Integer;
Item: TAdvSelectorItem);
begin
if Assigned(FRich) then
FRich.SelAttributes.Color := FColorSelector.SelectedColor;
end;
end.
sizce nerede hata yapiyorum?
selam ve dua ile...