Summary: Describes how to write a custom control that is used on a form in a report (such as Edit,button, etc.)
Writing Custom Common Controls
Fastreport contains a set of common controls which can be placed on dialogue forms inside reports. They is as follows:
The fastreport contains the following controls for the dialog form form in the report.
Tfrxlabelcontrol
Tfrxeditcontrol
Tfrxmemocontrol
Tfrxbuttoncontrol
Tfrxcheckboxcontrol
Tfrxradiobuttoncontrol
Tfrxlistboxcontrol
Tfrxcomboboxcontrol
Tfrxdateeditcontrol
Tfrximagecontrol
Tfrxbevelcontrol
Tfrxpanelcontrol
Tfrxgroupboxcontrol
Tfrxbitbtncontrol
Tfrxspeedbuttoncontrol
Tfrxmaskeditcontrol
Tfrxchecklistboxcontrol
These controls correspond to the Delphi component palette standard controls. If The standard functionality isn't sufficient then you can create your own common controls for use in your reports.
These controls are consistent with the Delphi standard control, and you can write your own control if it doesn't meet your needs.
The base class for all common controls are the "Tfrxdialogcontrol" class, declared in the Frxclass file:
(using base class Tfrxdialogcontrol)
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;
The property is Visible;
End
To create your own control should inherit from this class and override at least the constructor and the "Getdescriptio N "method. It is necessary to create the common control and initialize it using the ' Initcontrol ' method in the constructor. The GetDescription method is for returning a description of the common control. As can see the Tfrxdialogcontrol class already have a large number of properties and methods in the public section. Move properties and events into the ' published ' section of your common control as required and also create new properties That is specific to your control.
Writing custom controls should inherit from the class Tfrxdialogcontrol and at least override the constructor and GetDescription methods.
Common control registration and deletion is performed by using the Frxobjects global object methods declared in the FRXDSG nintf file:
Controls are registered and deleted using the global method Frxobjects, in the frxdsgnintf file.
Frxobjects.registerobject (Classref:tfrxcomponentclass; BUTTONBMP:TBITMAP);
Frxobjects.unregister (Classref:tfrxcomponentclass);
During registration You should specify the control class name and its picture. The buttonbmp size should be 16x16 pixels.
During the registration process, you should specify the control class name and its picture. The size of the buttonbmp should be 16x16 pixels.
Let's look at a example of a common control which simplifies the functionality of the standard Delphi tbitbtn control.
Let's write a simple example that implements the standard Delphi control TBITBTN functionality.
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 is 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); Initializing objects
{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
Registered
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.
Translation Writing Custom Common Controls