摘要:介绍如何编写自定义的控件,用在报表的窗体上(如Edit,Button等)

 

Writing Custom Common Controls 编写自定义控件

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

FastReport包含以下控件,用于报表里的对话形式窗体。

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 is not sufficient then you can create your own common controls for use in your reports.

这些控件跟DELPHI标准控件一致,如果不能满足需求,可以自己编写控件。

The base class for all common controls is the “TfrxDialogControl” class, declared in the frxClass file:

(使用基类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;

property Visible;

end;

 

To create your own control you should inherit from this class and override at least the constructor and the “GetDescription” method. It will be 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 you can see the TfrxDialogControl class already has 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 are specific to your control.

编写自定义的控件应该从类TfrxDialogControl继承,并至少要重写constructor 和GetDescription方法。

 

Common control registration and deletion is performed by using the frxObjects global object methods declared in the frxDsgnIntf file:

控件的注册和删除使用全局方法frxObjects,方法在frxDsgnIntf 文件中。

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.

在注册过程中,你应该指定控制类名称和它的图片。ButtonBmp的尺寸应为16X16像素。

 

Let's look at an example of a common control that simplifies the functionality of the standard Delphi TBitBtn control.

让我们编写一个简单的例子,实现标准的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.

[翻译]Writing Custom Common Controls 编写自定义控件的更多相关文章

  1. [翻译]Writing Custom DB Engines 编写定制的DB引擎

    Writing Custom DB Engines  编写定制的DB引擎   FastReport can build reports not only with data sourced from ...

  2. [翻译]Writing Custom Report Components 编写自定义报表组件

    摘要:简单介绍了如何编写一个FastReport的组件,并且注册到FastReport中使用.   Writing Custom Report Components 编写自定义报表组件 FastRep ...

  3. [翻译]Writing Custom Wizards 编写自定义的向导

    Writing Custom Wizards  编写自定义的向导   You can extend FastReport's functionality with the help of custom ...

  4. Qt编写自定义控件二动画按钮

    现在的web发展越来越快,很多流行的布局样式,都是从web开始的,写惯了Qt widgets 项目,很多时候想改进一下现有的人机交互,尤其是在现有的按钮上加一些动画的效果,例如鼠标移上去变大,移开还原 ...

  5. [翻译]Writing Component Editors 编写组件的编辑器

    Writing Component Editors  编写组件的编辑器   All common control editors (opened from a control's context me ...

  6. [翻译] Writing Property Editors 编写属性编辑器

    Writing Property Editors 编写属性编辑器   When you select a component in the designer its properties are di ...

  7. (译)Getting Started——1.3.4 Writing a Custom Class(编写自定义的类)

     在开发IOS应用中,当你编写自定义的类时,你会发现很多的特殊场合.当你需要把自定义的行为和数据包装在一起时,自定义的类非常有用.在自定义的类中,你可以定义自己的存储.处理和显示数据的方法. 例如,I ...

  8. 编写Qt Designer自定义控件(二)——编写自定义控件界面

    接上文:编写Qt Designer自定义控件(一)——如何创建并使用Qt自定义控件 既然是控件,就应该有界面,默认生成的控件类只是一个继承了QWidget的类,如下: #ifndef LOGLATED ...

  9. Delphi编写自定义控件以及接口的使用(做了一个TpgDbEdit)

    写给觉得自己编写Delphi很复杂的人,包括自己. Delphi自己写控件其实并不难,难的在于开发复杂的控件.(其实,编程,很多东西都是会了就不难,因此,我怕自己日后觉得自己写控件很难,特意在这记录自 ...

随机推荐

  1. Quick guide for converting from JAGS or BUGS to NIMBLE

    Converting to NIMBLE from JAGS, OpenBUGS or WinBUGS NIMBLE is a hierarchical modeling package that u ...

  2. 030:Cetus中间件和MHA读写分离

    030:Cetus中间件和MHA读写分离 line:V1.1 mail: gczheng@139.com date: 2018-08-30 一.主机环境 虚拟机配置 CPU 内存 硬盘 OS版本 My ...

  3. nodejs+express+ejs+mongoose实例

    nodejs+express+ejs+mongoose实例 nodejs学得异常痛苦,在这里将学的东西做一番整理,算是自我安慰吧.根据网上todo示例,用express和mongoose重写了部分代码 ...

  4. HDU 1043 八数码问题的多种解法

    一.思路很简单,搜索.对于每一种状态,利用康托展开编码成一个整数.于是,状态就可以记忆了. 二.在搜索之前,可以先做个优化,对于逆序数为奇数的序列,一定无解. 三.搜索方法有很多. 1.最普通的:深搜 ...

  5. 【BZOJ】1756: Vijos1083 小白逛公园(线段树)

    题目 传送门:QWQ 分析 线段树维护一下最大子序列 维护一下最大前缀 最大后缀  区间和 就ok了 好像只能用结构体..... 代码 #include <bits/stdc++.h> u ...

  6. icape3 的使用

    在FPGA中,有时需要使用用户代码重配置FPGA,配置的内容可以是flash或者是其他的来源这样FPGA的启动模式有关,在本实验中配置文件是存放在flash中.实际的操作步骤如下: 1:生成一个工程, ...

  7. DSL与编译原理

    DSL:领域语言 类似于SQL的一种语言,比如自创一种语言,如何解析 可以自己实现类似于一种语言: 比如hibernate里面的sql解析就使用ANTLR 比如:http://hellojinjie. ...

  8. 接口自动化(二)--操作Excel获取需要数据

    这一部分的内容记述一下对Excel表格的操作,本实战中的测试用例是由Excel来管理的,因此操作Excel是重要的一部分. 再次贴出这张图,所有的测试用例都在这个sheet内,请求数据真实存放在jso ...

  9. MySQL备份恢复全实战

    一. 简介 1. 增量备份 增量备份是指在一次全备份或上一次增量备份后,以后每次的备份只需备份与前一次相比增加或者被修改的文件.这就意味着,第一次增量 备份的对象是进行全备后所产生的增加和修改的文件; ...

  10. vlc相关命令行设置

    1:改变VLC模块参数   http://tianxiaoma.blog.51cto.com/1501174/309519 ====================================== ...