原創|其它|編輯:郝浩|2012-11-27 14:21:10.000|閱讀 908 次
概述:FastReport VCL報表控件中包含了一組可放置在報表內部對話框窗體中的常用控件。本文主要介紹如何編寫自定義常見控件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
FastReport VCL報表控件中包含了一組可放置在報表內部對話框窗體中的常用控件。它們分別是:
這些組件對應了Delphi組件面板標準控件。如果標準功能還不能滿足需要的話,你可以在報表中創建你自己的常用控件。
“TfrxDialogControl”是適合所有常用控件的基類,在frxClass文件中,對其進行了聲明:
TfrxDialogControl = class(TfrxReportComponent)
protected
procedure InitControl(AControl: TControl);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
class function GetDescription: String; virtual;
property Caption: String;
property Color: TColor;
property Control: TControl;
property OnClick: TfrxNotifyEvent;
property OnDblClick: TfrxNotifyEvent;
property OnEnter: TfrxNotifyEvent;
property OnExit: TfrxNotifyEvent;
property OnKeyDown: TfrxKeyEvent;
property OnKeyPress: TfrxKeyPressEvent;
property OnKeyUp: TfrxKeyEvent;
property OnMouseDown: TfrxMouseEvent;
property OnMouseMove: TfrxMouseMoveEvent;
property OnMouseUp: TfrxMouseEvent;
published
property Left;
property Top;
property Width;
property Height;
property Font;
property ParentFont;
property Enabled: Boolean;
property Visible;
end;
要創建屬于你自己的常用控件,你可以從“TfrxDialogControl”中繼承,重載構造函數和 “GetDescription” 方法。GetDescription 方法用于返回常用控件的描述。正如你所知道的, TfrxDialogControl類擁有大量的屬性和方法。根據需要將屬性和事件移到常用控件的 “published”部分,還可以創建新的屬性,并將其指定到你的控件中。
根據frxDsgnIntf文件中聲明的frxObjects global object方法,可以實現常用控件的注冊和刪除。
frxObjects.RegisterObject(ClassRef: TfrxComponentClass;
ButtonBmp: TBitmap);
frxObjects.Unregister(ClassRef: TfrxComponentClass);
注冊期間,你應該指定控件類名和圖片。ButtonBmp大小應該為16x16像素。
下面是一個關于常用控件的示例,簡化了標準的Delphi TBitBtn控件的功能:
uses frxClass, frxDsgnIntf, Buttons;
type
TfrxBitBtnControl = class(TfrxDialogControl)
private
FButton: TBitBtn;
procedure SetKind(const Value: TBitBtnKind);
function GetKind: TBitBtnKind;
public
constructor Create(AOwner: TComponent); override;
class function GetDescription: String; override;
property Button: TBitBtn read FButton;
published
{ add new properties }
property Kind: TBitBtnKind read GetKind
write SetKind default bkCustom;
{ following properties are already declared in parent class }
property Caption;
property OnClick;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
constructor TfrxBitBtnControl.Create(AOwner: TComponent);
begin
{ default constructor }
inherited;
{ create required common control }
FButton := TBitBtn.Create(nil);
FButton.Caption := 'BitBtn';
{ initialize it }
InitControl(FButton);
{ set default size }
Width := 75;
Height := 25;
end;
class function TfrxBitBtnControl.GetDescription: String;
begin
Result := 'BitBtn control';
end;
procedure TfrxBitBtnControl.SetKind(const Value: TBitBtnKind);
begin
FButton.Kind := Value;
end;
function TfrxBitBtnControl.GetKind: TBitBtnKind;
begin
Result := FButton.Kind;
end;
var
Bmp: TBitmap;
initialization
Bmp := TBitmap.Create;
{ load picture from resource;
it should have already been placed there, of course }
Bmp.LoadFromResourceName(hInstance, 'frxBitBtnControl');
frxObjects.RegisterObject(TfrxBitBtnControl, Bmp);
finalization
frxObjects.Unregister(TfrxBitBtnControl);
Bmp.Free;
end.
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn