How to use own function?

王朝other·作者佚名  2006-01-09
宽屏版  字体: |||超大  

Use TfrReport.OnUserFunction event. Here is simple example:

procedure TForm1.frReport1UserFunction(const Name: String;

p1, p2, p3: Variant; var val: Variant);

begin

ifAnsiCompareText('SUMTOSTR', Name) = 0then

val := My_Convertion_Routine(frParser.Calc(p1));

end;

After this, you can use SumToStr function in any place of report (in any expression or script).

(ok, but it works only for one TfrReport component. I want to use my function everywhere (in all TfrReport components).

Make OnUserFunction event handler common for all components. If you can't do this, you should create function library:

type

TMyFunctionLibrary = class(TfrFunctionLibrary)

public

constructor Create; override;

procedure DoFunction(FNo: Integer; p1, p2, p3: Variant;

var val: Variant); override;

end;

constructor MyFunctionLibrary.Create;

begin

inherited Create;

with List do

begin

Add('DATETOSTR');

Add('SUMTOSTR');

end;

end;

procedure TMyFunctionLibrary.DoFunction(FNo: Integer;

p1, p2, p3: Variant; var val: Variant);

begin

val := 0;

case FNo of

0: val := My_DateConvertion_Routine(frParser.Calc(p1));

1: val := My_SumConvertion_Routine(frParser.Calc(p1));

end;

end;

To register function library, call

frRegisterFunctionLibrary(TMyFunctionLibrary);

To unregister library, call

frUnRegisterFunctionLibrary(TMyFunctionLibrary);

(how I can add my function to function list (in expression builder)?

Use frAddFunctionDesc procedure (FR_Class unit):

frAddFunctionDesc('SUMTOSTR', 'My functions',

'SUMTOSTR()/Converts number to its verbal presentation.');

Note: "/" symbol is required! It separates function syntax from its description.

FuncLib is reference to your function library (can be nil if you don't use the function library). When function library is unregistered, all its function will be automatically removed from the function list.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有