Search Results for

    Show / Hide Table of Contents

    Custom Common Controls Writing

    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);
    frxObjects.Unregister(ClassRef: TfrxComponentClass);
    

    During registration you should specify control class name and its picture. ButtonBmp size should be 16x16 pixels.

    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.
    
    Back to top © 1998-2022 Copyright Fast Reports Inc.