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

本文介绍如何使用FastReport创建自定义向导以扩展其功能。通过继承TfrxCustomWizard类并重写必要方法,可以轻松实现如添加报告页面等操作。文中还提供了向导注册的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Writing Custom Wizards  编写自定义的向导

 

You can extend FastReport's functionality with the help of custom wizards. FastReport, for example, contains the standard “Report Wizard” which is called from the “File >|New…” menu item.

There are two types of wizards supported by FastReport. The first type includes the wizard already mentioned, called from the “File>New…” menu item. The second one includes wizards that can be called from the “Wizards” toolbar.

The base class for any wizard is “TfrxCustomWizard”, defined in the “frxClass” file.

TfrxCustomWizard = class(TComponent)

Public

Constructor Create(AOwner: TComponent); override;

class function GetDescription: String; virtual; abstract;  //需要实现

function Execute: Boolean; virtual; abstract;   //需要实现

property Designer: TfrxCustomDesigner read FDesigner;

property Report: TfrxReport read FReport;

end;

To write your own wizard inherit from this class and override at least the “GetDescription” and “Execute” methods. The first method returns the wizard name; the second method is called when running the wizard; it must return “True” if the wizard finished successfully and made any changes to the report. While the wizard is running you can access designer and report methods and properties as normal using the “Designer” and “Report” properties.

 

Wizard registration and deletion is performed using the procedures defined in the “frxDsgnIntf” file:

向导的注册用以下方法,声明在frxDsgnIntf文件:

frxWizards.Register(ClassRef: TfrxWizardClass; ButtonBmp: TBitmap;IsToolbarWizard: Boolean = False);

frxWizards.Unregister(ClassRef: TfrxWizardClass);

On registration supply the wizard class name, its picture and whether the wizard is to be placed on the “Wizards” toolbar. If the wizard should be placed on the toolbar the ButtonBmp size must be either 16x16 pixels or 32x32 pixels.

//举例

Let's look at a primitive wizard that will be accessed through the "File>New..." menu item. It adds a new page to a report.

uses frxClass, frxDsgnIntf;

type

TfrxMyWizard = class(TfrxCustomWizard)

public

//需要重写的方法

class function GetDescription: String; override;

function Execute: Boolean; override;

end;

class function TfrxMyWizard.GetDescription: String;

begin

Result := 'My Wizard';

end;

function TfrxMyWizard.Execute: Boolean;

var

Page: TfrxReportPage;

begin

{ lock any drawings in designer }

Designer.Lock;

{ create new page in report }

Page := TfrxReportPage.Create(Report);

{ create unique name for page }

Page.CreateUniqueName;

{ set paper sizes and orientation to defaults }

Page.SetDefaults;

{ update report pages and switch focus to last added page }

Designer.ReloadPages(Report.PagesCount - 1);

end;

 

//注册

var

Bmp: TBitmap;

initialization

Bmp := TBitmap.Create;

{ load picture from resource; of course, it must already be there }

Bmp.LoadFromResourceName(hInstance, 'frxMyWizard');

frxWizards.Register(TfrxMyWizard, Bmp);

finalization

frxWizards.Unregister(TfrxMyWizard);

Bmp.Free;

end.

转载于:https://www.cnblogs.com/moon25/p/5531673.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值