Custom Common Controls Writing

Top  Previous  Next

Custom Common Controls Writing

Top Previous Next

 

FastReport contains a set of common controls, which can be placed on dialogue forms inside the report. They are as follows:

 

TfrxLabelControl

TfrxEditControl

TfrxMemoControl

TfrxButtonControl

TfrxCheckBoxControl

TfrxRadioButtonControl

TfrxListBoxControl

TfrxComboBoxControl

TfrxDateEditControl

TfrxImageControl

TfrxBevelControl

TfrxPanelControl

TfrxGroupBoxControl

TfrxBitBtnControl

TfrxSpeedButtonControl

TfrxMaskEditControl

TfrxCheckListBoxControl

 

These control elements correspond to Delphi component palette standard controls. If standard functionality does not satisfy you, you can create your own common control and use it in your reports.

 

Basic class for all common controls is TfrxDialogControl class declared in frxClass file:

 

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;

 

To create your own control element, you should inherit from this class and override at least the constructor and “GetDescription” methods. It will be necessary to create common control and initialize it via “InitControl” method in constructor. GetDescription method is to return common control description. As you can see from TfrxDialogControl class description, it already contains huge number of properties and methods in public section. You need to transfer any necessary properties/events into “published” section of your common control, and also to create new properties, which are typical for your element.

 

Common control registration and deleting is performed via frxObjects global object methods declared in frxDsgnIntf file:

 

frxObjects.RegisterObject(ClassRef: TfrxComponentClass; ButtonBmp: TBitmap; const CategoryName: String = '');

frxObjects.Unregister(ClassRef: TfrxComponentClass);

 

During registration you should specify control class name, its picture, and the name of the category, in which it should be placed. If a category name is not specified, control will be placed in basic component palette. ButtonBmp size should be 22x22 pixels.

 

Categories allow grouping of objects pictures in the toolbar, according to their functions. Categories are also used for saving space in the toolbar, since its size is limited. Nevertheless, it can contain a large number of objects.

 

To register the category, use following method of “frxObjects” object declared in “frxDsgnIntf” file:

 

frxObjects.RegisterCategory(const CategoryName: String; ButtonBmp: TBitmap; const ButtonHint: String; ImageIndex: Integer = -1);

 

The first parameter is category name. This name is used for category identification only and does not appear anywhere else. It should also be used when calling the “frxObjects.RegisterObject” procedure, if you want to place registered object inside a given category. The second parameter is picture; its size is 22x22 pixels. The third parameter is category description; it is displayed as hint, if button with category is selected by cursor.

 

Let us examine the example of the common control, which has simplified functionality of the standard Delphi TBitBtn control, for example.

 

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;

  { these 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);

 

{ it will have such size by default }

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. Of course, you should beforehand place it there.}

Bmp.LoadFromResourceName(hInstance, 'frxBitBtnControl');

frxObjects.RegisterObject(TfrxBitBtnControl, Bmp);

 

finalization

frxObjects.Unregister(TfrxBitBtnControl);

Bmp.Free;

 

end.