Writing Component Editors  编写组件的编辑器

 

All common control editors (opened from a control's context menu or by double-clicking) create blank OnClick event handlers by default. This behavior can be altered by writing a custom editor. Also, the custom editor can add extra items to the component's context menu.

The base class for all editors is “TfrxComponentEditor”, declared in the frxDsgnIntf file:

所有的控件编辑(从一个控件的右键菜单或双击打开)默认创建空白的onclick事件处理程序。这种行为可以通过编写自定义编辑器来改变。另外,自定义编辑器可以添加额外的项目到组件的右键菜单中。所有编辑器基类是“TfrxComponentEditor”,在frxDsgnIntf 文件中声明:

 

TfrxComponentEditor = class(TObject)

protected

function AddItem(Caption: String; Tag: Integer;Checked: Boolean = False): TMenuItem;

public

function Edit: Boolean; virtual;

function HasEditor: Boolean; virtual;

function Execute(Tag: Integer; Checked: Boolean): Boolean; virtual;

procedure GetMenuItems; virtual;

property Component: TfrxComponent readonly;

property Designer: TfrxCustomDesigner readonly;

end;

 

If your editor does not create its own items in the contextual menu you will need to override two methods, “Edit” and “HasEditor.” The first method performs essential actions (for example, displays the dialogue box) and returns “True” if the component's content was modified. The “HasEditor” method should return “True” if your component has an editor. If it either returns “False” or the method is not overridden the editor will not be opened. It should return “False” if your component does not have an editor and you wish to add items to the component's context menu.

如果你的编辑器不创建项目右键菜单,你需要重写方法“Edit”和“HasEditor”。第一个方法执行必要的行动(例如,显示对话框并返回“True”,如果组件的内容被修改)。如果你的组件有一个编辑器,“HasEditor”方法应该返回“True”否则返回“假”或方法不重写编辑器将不被打开。

如果你的组件没有编辑器并且你希望将项目添加到组件的右键菜单中,则应该返回“False”。

 

If the editor adds items to the context menu you should override “GetMenuItems” (where you can create a menu using the AddItem function) and “Execute” (where you can create the actions initiated by selecting the items in the component menu).

如果编辑器添加项目到上下文菜单应该重写”GetMenuItems”(在那里你可以创建一个菜单使用AddItem函数)和“Execute”(在那里你可以创建actions 在构件菜单选择启动)。

 

Editor registration is performed using the procedure defined in the “frxDsgnIntf” file:

frxComponentEditors.Register(ComponentClass: TfrxComponentClass;ComponentEditor: TfrxComponentEditorClass);

The first parameter is the class name of the component for which the editor is being created. The second parameter is the class name of the editor.

编辑器的注册使用frxDsgnIntf单元的以下过程:

第一个参数是编辑器对应组件的类名,第二个参数是编辑器的类名。

Let's look at a simple editor for our common control, which will display a window with our element name and also add "Enabled" and "Visible" items to control's context menu (which change the “Enabled” and “Visible” properties). FastReport requires that the Editor code is placed in a file having the same name as the file having the component’s code, with 'Editor' added as suffix (frxBitBtnEditor.pas in our case).

让我们看一个简单的控件的编辑器,将用我们的元素名称显示一个窗口,还添加“Enabled”和“Visible”的项目,以控制的上下文菜单(改变了“Enabled”和“Visible”属性)。FastReport要求编辑器文件跟组件文件放置在一起,并用“Editor”作为后缀(frxbitbtneditor.pas在这个例子中)。

 

uses frxClass, frxDsgnIntf, frxBitBtn;

type

TfrxBitBtnEditor = class(TfrxComponentEditor)

public

//重写的方法

function Edit: Boolean; override;

function HasEditor: Boolean; override;

function Execute(Tag: Integer; Checked: Boolean): Boolean; override;

procedure GetMenuItems; override;

end;

function TfrxBitBtnEditor.Edit: Boolean;

var

c: TfrxBitBtnControl;

begin

Result := False;

{ Component property is edited component; in this case, it is TfrxBitBtnControl }

c := TfrxBitBtnControl(Component);

ShowMessage('This is ' + c.Name);

end;

function TfrxBitBtnEditor.HasEditor: Boolean;

begin

Result := True;

end;

function TfrxBitBtnEditor.Execute(Tag: Integer; Checked: Boolean): Boolean;

var

c: TfrxBitBtnControl;

begin

Result := True;

c := TfrxBitBtnControl(Component);

if Tag = 1 then

c.Enabled := Checked

else if Tag = 2 then

c.Visible := Checked;

end;

procedure TfrxBitBtnEditor.GetMenuItems;

var

c: TfrxBitBtnControl;

begin

c := TfrxBitBtnControl(Component);

{ AddItem method parameters: menu item name, its tag and Checked/Unchecked condition }

AddItem('Enabled', 1, c.Enabled);

AddItem('Visible', 2, c.Visible);

end;

initialization

frxComponentEditors.Register(TfrxBitBtnControl, TfrxBitBtnEditor);

end.

 

可以参考 frxRichEditor.pas 等单元。

[翻译]Writing Component Editors 编写组件的编辑器的更多相关文章

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

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

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

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

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

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

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

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

  5. 为Node.js编写组件的几种方式

    本文主要备忘为Node.js编写组件的三种实现:纯js实现.v8 API实现(同步&异步).借助swig框架实现. 关键字:Node.js.C++.v8.swig.异步.回调. 简介 首先介绍 ...

  6. [翻译]Writing Custom Common Controls 编写自定义控件

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

  7. [翻译] FastReport Class Hierarchy (FastReport 组件类层次结构)

    "TfrxComponent" is the base class for all FastReport components. Objects of this type have ...

  8. react 编写组件 五

    看以下示例了解如何定义一个组件 // 定义一个组件LikeButton var LikeButton = React.createClass({ // 给state定义初始值 getInitialSt ...

  9. Gradle 1.12 翻译——第十三章 编写构建脚本

    有关其它已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或訪问:http://gradledoc.qiniudn.com ...

随机推荐

  1. "废物利用"也抄袭——“完全”DIY"绘图仪"<二、下位机程序设计>

    就不说怎么组装了吧,一把辛酸泪.说程序,因为这有两把辛酸泪……一把给下位机的C代码一把为了VB.NET的图像处理……不过就上上一篇说的,它们可以正确运行了,并且今天克服了Arduino上电过程中步进电 ...

  2. java批量下载,将多文件打包成zip格式下载

    现在的需求的: 根据产品族.产品类型,下载该产品族.产品类型下面的pic包: pic包是zip压缩文件: t_product表: 这些包以blob形式存在另一张表中: t_imagefile表: 现在 ...

  3. 利用VMware在虚拟机上安装Zookeeper集群

    http://blog.csdn.net/u010246789/article/details/52101026 利用VMware在虚拟机上安装Zookeeper集群 pasting

  4. pycharm -- 小技巧1 (显示文件的代码结构以及错误提示)

    背景介绍 今天上午,在调用同事昨天给的算法程序时出了点问题,于是请同事来我这边一起调代码.大致场景描述如下: 我:B神,你昨天下班前给我的那个算法程序我这边调用的时候出现错误啦,请你过来看下呗. 同事 ...

  5. 使用Java配置SpringMVC

    在此之前,一直使用的是XML的方式配置SpringMVC,现在为了适应Servlert3.0以及JavaConfig的Spring配置方式,在这里记录一下使用Java代码配置SpringMVC.首先, ...

  6. C++11新特性介绍 02

    阅读目录 1. 范围for语句 2. 尾置返回类型 3. =default 生成默认构造函数 4. 类对象成员的类内初始化 5. lambda表达式与bind函数 6. 智能指针share_ptr,u ...

  7. 在Windows命令行窗口中输入并运行PHP代码片段(不需要php文件)的方法

    有时候只是简单的为了测试某个php函数的效果,以前总是需要建一个php文件,复制这个文件的路径,再通过web访问或者用php命令执行这个php文件. 一直想要怎么才能不用创建文件,才能直接执行PHP代 ...

  8. pandas read_csv读取大文件的Memory error问题

    今天在读取一个超大csv文件的时候,遇到困难:首先使用office打不开然后在python中使用基本的pandas.read_csv打开文件时:MemoryError 最后查阅read_csv文档发现 ...

  9. Jenkins是什么?

    Jenkins 是一个可扩展的持续集成引擎. 主要用于: l 持续.自动地构建/测试软件项目. l 监控一些定时执行的任务. Jenkins拥有的特性包括: l 易于安装-只要把jenkins.war ...

  10. Git----分支管理01

    分支就是科幻电影里面的平行宇宙,当你正在电脑前努力学习Git的时候,另一个你正在另一个平行宇宙里努力学习SVN. 如果两个平行宇宙互不干扰,那对现在的你也没有啥影响,不过,在某个时间点,两个平行宇宙合 ...