[翻译]Writing Custom Report Components 编写自定义报表组件
摘要:简单介绍了如何编写一个FastReport的组件,并且注册到FastReport中使用。
Writing Custom Report Components 编写自定义报表组件
FastReport has a large number of components that can be placed on a report design page. They are: text, picture, line, geometrical figure, OLE, rich text, bar code, diagram etc. You can also write your own custom component and then attach it to FastReport.
FastReport有很多放在报表设计页上的组件,他们是text,picture等,你可以编写自定义的组件并附加到FastReport。
FastReport has several classes from which components can be inherited. For more details, see “FastReport Class Hierarchy”. The TfrxView class is of primary interest, since most report components are inherited from it.
(选择合适的基类继承)
As a minimum the “Draw” method in the TfrxReportComponent base class should be defined.
procedure Draw(Canvas: TCanvas;ScaleX, ScaleY, OffsetX, OffsetY: Extended); virtual;
This method is called when the component is painted in the designer, in the preview window and during output printing. TfrxView overrides this method for drawing the object frame and background. This method should draw the component's contents on the “Canvas” drawing surface. The object coordinates and sizes are stored in the “AbsLeft”, “AbsTop” and “Width”, “Height” properties respectively.
(编写组件就是重写Draw方法)
The “ScaleX” and “ScaleY” parameters define the object scaling in the X-axis and Y-axis respectively. These parameters equal 1 at 100% zoom and can change if the user modifies zooming either in the designer or in the preview window. The “OffsetX” and “OffsetY” parameters shift the object along the X-axis and Y-axis. So, taking all these parameters into account the upper left corner coordinate will be:
(缩放)
X := Round(AbsLeft * ScaleX + OffsetX);
Y := Round(AbsTop * ScaleY + OffsetY);
To simplify operations with coordinates, the “BeginDraw” method (with parameters similar to “Draw”) is defined in the “TfrxView” class.
procedure BeginDraw(Canvas: TCanvas;ScaleX, ScaleY, OffsetX, OffsetY: Extended); virtual;
This method should be called in the first line of the “Draw” method. It transforms the coordinates into FX, FY, FX1, FY1, FDX, FDY and FFrameWidth integer values, which can be used later in TCanvas methods. It also copies Canvas, ScaleX and ScaleY values into the FCanvas, FScaleX and FScaleY variables, which can be referred to in any class method.
(重写BeginDraw方法)
There are also two methods in the TfrxView class for drawing object backgrounds and frames.
procedure DrawBackground;
procedure DrawFrame;
The BeginDraw method should be called before calling these two methods.
Let's look at how to create a component which will display an arrow.
让我们来看看如何创建一个组件,它将显示一个箭头。
type
TfrxArrowView = class(TfrxView) //根据需求选择不同的基类
public
{ we should override only two methods }
procedure Draw(Canvas: TCanvas;ScaleX, ScaleY, OffsetX, OffsetY: Extended); override; //重写Draw方法
class function GetDescription: String; override;
published
{ place required properties in the published section } //公布需要的属性
property BrushStyle;
property Color;
property Frame;
end;
class function TfrxArrowView.GetDescription: String;
begin
{ component description will be displayed next to its icon in toolbar }
Result := 'Arrow object';
end;
procedure TfrxArrowView.Draw(Canvas: TCanvas;ScaleX, ScaleY, OffsetX, OffsetY: Extended);
begin
{ call this method to transform coordinates } // 调用BeginDraw方法来转换坐标
BeginDraw(Canvas, ScaleX, ScaleY, OffsetX, OffsetY);
with Canvas do
begin
{ set colors }
Brush.Color := Color;
Brush.Style := BrushStyle;
Pen.Width := FFrameWidth;
Pen.Color := Frame.Color;
{ draw arrow }
Polygon(
[Point(FX, FY + FDY div 4),
Point(FX + FDX * 38 div 60, FY + FDY div 4),
Point(FX + FDX * 38 div 60, FY),
Point(FX1, FY + FDY div 2),
Point(FX + FDX * 38 div 60, FY1),
Point(FX + FDX * 38 div 60, FY + FDY * 3 div 4),
Point(FX, FY + FDY * 3 div 4)]);
end;
end;
{ registration } //注册组件
var
Bmp: TBitmap;
initialization
Bmp := TBitmap.Create;
Bmp.LoadFromResourceName(hInstance, 'frxArrowView');
frxObjects.RegisterObject(TfrxArrowView, Bmp); // frxObjects是函数,在frxDsgnIntf单元 TfrxObjectCollection
finalization
{ delete from list of available components }
frxObjects.Unregister(TfrxArrowView);
Bmp.Free;
end.
To create a component which displays data from a DB move the DataSet and DataField properties into the “published” section and then override the “GetData” method. Let's look at this by using the TfrxCheckBoxView standard component as an example.
创建一个从数据集显示数据的组件,移动DataSet和DataField属性到“published”部分,然后重写“GetData”方法。让我们用Tfrxcheckboxview标准组件为例看看。
The “TfrxCheckBoxView” component can be connected to a DB field using the “DataSet” and “DataField” properties, which are declared in the TfrxView base class. This component also has the “Expression” property which can hold an expression. As soon as the expression has been calculated the result is placed in the “Checked” property. The component displays a cross when “Checked” is “True.” Below are the most important parts of the component’s definition.
TfrxCheckBoxView = class(TfrxView)
private
FChecked: Boolean;
FExpression: String;
procedure DrawCheck(ARect: TRect);
public
procedure Draw(Canvas: TCanvas;ScaleX, ScaleY, OffsetX, OffsetY: Extended); override; //重写
procedure GetData; override; //重写
published
property Checked: Boolean read FChecked write FChecked default True;
property DataField;
property DataSet;
property Expression: String read FExpression write FExpression;
end;
procedure TfrxCheckBoxView.Draw(Canvas: TCanvas;ScaleX, ScaleY, OffsetX, OffsetY: Extended);
begin
BeginDraw(Canvas, ScaleX, ScaleY, OffsetX, OffsetY);
DrawBackground;
DrawCheck(Rect(FX, FY, FX1, FY1));
DrawFrame;
end;
procedure TfrxCheckBoxView.GetData;
begin
inherited;
if IsDataField then
FChecked := DataSet.Value[DataField]
else if FExpression <> '' then
FChecked := Report.Calc(FExpression);
end;
[翻译]Writing Custom Report Components 编写自定义报表组件的更多相关文章
- [翻译]Writing Custom DB Engines 编写定制的DB引擎
Writing Custom DB Engines 编写定制的DB引擎 FastReport can build reports not only with data sourced from ...
- [翻译]Writing Custom Common Controls 编写自定义控件
摘要:介绍如何编写自定义的控件,用在报表的窗体上(如Edit,Button等) Writing Custom Common Controls 编写自定义控件 FastReport contains ...
- [翻译]Writing Custom Wizards 编写自定义的向导
Writing Custom Wizards 编写自定义的向导 You can extend FastReport's functionality with the help of custom ...
- (译)Getting Started——1.3.4 Writing a Custom Class(编写自定义的类)
在开发IOS应用中,当你编写自定义的类时,你会发现很多的特殊场合.当你需要把自定义的行为和数据包装在一起时,自定义的类非常有用.在自定义的类中,你可以定义自己的存储.处理和显示数据的方法. 例如,I ...
- [翻译] Using Custom Functions in a Report 在报表中使用自己义函数
Using Custom Functions in a Report 在报表中使用自己义函数 FastReport has a large number of built-in standard ...
- [翻译]Writing Component Editors 编写组件的编辑器
Writing Component Editors 编写组件的编辑器 All common control editors (opened from a control's context me ...
- Kubernetes 编写自定义 controller
原文链接:Kubernetes编写自定义controller 来自kubernetes官方github的一张图: 如图所示,图中的组件分为client-go和custom controller两部分: ...
- django “如何”系列4:如何编写自定义模板标签和过滤器
django的模板系统自带了一系列的内建标签和过滤器,一般情况下可以满足你的要求,如果觉得需更精准的模板标签或者过滤器,你可以自己编写模板标签和过滤器,然后使用{% load %}标签使用他们. 代码 ...
- SpringBoot编写自定义的starter 专题
What’s in a name All official starters follow a similar naming pattern; spring-boot-starter-*, where ...
随机推荐
- 修改Gradle 和Maven本地仓库的位置方法
本文转载自:https://www.cnblogs.com/dwb91/p/6523541.html 关于Maven的配置: 用过Maven的开发人员应该知道Maven可以通过配置 conf文件夹下面 ...
- mysql-6正则表达式
mysql正则表达式 匹配的两种方式: 1.模糊匹配:like 2.正则表达式 正则表达式语法: 语法 说明 ^ 起始位置.如果设置了RegExp对象的Multiline属性,^也匹配'\n'或'\r ...
- laravel上传文件到七牛云存储
背景 最近在用PHP和laravel框架做一个图片网站,需要将图片存贮到云端,搜索下了对比了下功能,发现七牛云存储不错(主要小流量免费),便选择使用七牛作为图片存储空间. 要实现的功能很简单,选择本地 ...
- Spring MVC的困惑url-pattern /和/*的区别
今天在写项目时发现一个spring 总是报org.springframework.web.servlet.DispatcherServlet noHandlerFound警告: No mapping ...
- python爬虫----基本操作
一.爬虫基本操作 有些网站和其他网站是有关系(链接),全球的网站就相当于一个蜘蛛网,我们放一只蜘蛛在上面爬,一定能够把网爬个遍.那么如果我们要爬取互联网上内容我们就相当于放一只蜘蛛在上面. 爬虫分为 ...
- Shell脚本的特性
bash shell特性 1.命令补全和文件路径补全, 如果写错无法补全 table 2.命令历史记忆功能history 3.别名功能alias.unalias 4.常用快捷键ctrl+u,k,a,e ...
- CDN理解<转>
CDN则是更高级的手段.CDN到底如何工作的呢,让我们来大概了解一下! CDN的基础百科资料也很多了,我也稍等提一下.CDN,Content Distribute Network,即:内容分发网络. ...
- [译]2D空间中使用四叉树Quadtree进行碰撞检测优化
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Unity2017.2.0f3 原文出处 : Quick Tip: Use Quadtrees to Detect Lik ...
- js中获取父节点,兄弟节点及处理属性节点
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- windchill 跑物料变更流程后无法发送物料到SAP
2042000065.2042000064.2042000074.2042000066在发主数据时,流程卡住,SAP返回信息为空 核查:PLM后台日志只显示变更零件,开始,然后就结束 原因:ECR号为 ...