FastReport VCL报表控件开发者手册二:编写自定义常用控件

mac2022-06-30  69

FastReport VCL报表控件中包含了一组可放置在报表内部对话框窗体中的常用控件。它们分别是:

TfrxLabelControlTfrxEditControlTfrxMemoControlTfrxButtonControlTfrxCheckBoxControlTfrxRadioButtonControlTfrxListBoxControlTfrxComboBoxControlTfrxDateEditControlTfrxImageControlTfrxBevelControlTfrxPanelControlTfrxGroupBoxControlTfrxBitBtnControlTfrxSpeedButtonControlTfrxMaskEditControlTfrxCheckListBoxControl

这些组件对应了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.

 

转载于:https://www.cnblogs.com/FastReport/archive/2012/11/30/2796216.html

相关资源:FastReport VCL Enterprise (ClientServer) 6.3.11 Full Source
最新回复(0)