1. Q: How I can add my own function? A: Use TfrReport.OnUserFunction event. Here is simple example: procedure TForm1.frReport1UserFunction(const Name: String; p1, p2, p3: Variant; var val: Variant); begin if AnsiCompareText('SUMTOSTR', Name) = 0 then 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). Q: Ok, but it works only for one TfrReport component. I want to use my function everywhere (in all TfrReport components). A: 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 TMyFunctionLibrary.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); Q: How I can add my function to function list (in expression builder)? A: Use frAddFunctionDesc procedure (FR_Class unit): frAddFunctionDesc(FuncLib, 'SUMTOSTR', 'My functions', 'SUMTOSTR(<Number>)/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 function library). When function library is unregistered, all its function will be automatically removed from function list.2. [Query1.DataSetName."Field"] + [Query2.DataSetName."Field"]
3. Q: How I can transfer data to the report? A: There is several methods to do this. First is to use global object frVariables (defined in FR_Class unit): frVariables['My variable'] := 10; This code creates new variable with 'My variable' name and value = 10. This method is best to transfer static data to the report. Second method is to use TfrReport.OnGetValue event. You can use this method to transfer dynamic data, i.e. data which changes from record to record. procedure TForm1.frReport1GetValue(ParName: String; var ParValue: Variant); begin if ParName = 'MyField' then ParValue := Table1MyField.Value; end; Finally, third method is to define variable from dictionary programmatically (see previous question): with frReport1.Dictionary do begin Variables['MyVariable'] := 'CustomerData.Customers."CustNo"'; Variables['Another Variable'] := '10'; end;
1. Q: How I can add my own function? //怎樣加入自定義函數? A: Use TfrReport.OnUserFunction event. Here is simple example: //使用TfrReport的OnUserFunction事件處理過程.例: procedure TForm1.frReport1UserFunction(const Name: String; p1, p2, p3: Variant; var val: Variant); begin if AnsiCompareText('SUMTOSTR', Name) = 0 then 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).//此后,即可在報表中任何地方使用SumToStr 函數(自定義) Q: Ok, but it works only for one TfrReport component. I want to use my function everywhere (in all TfrReport components). //上面的做法只能在一個TfrReport組件中使用,如果在所有的TfrReport組件都可以使用應怎樣處理. A: Make OnUserFunction event handler common for all components. If you can't do this, you should create function library: //使OnUserFunction 事件對所有組件共用,若不能實現,應該建立函數庫: type TMyFunctionLibrary = class(TfrFunctionLibrary) public constructor Create; override; procedure DoFunction(FNo: Integer; p1, p2, p3: Variant; var val: Variant); override; end; constructor TMyFunctionLibrary.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); Q: How I can add my function to function list (in expression builder)?//怎樣把自定義函數加入函數列表? A: Use frAddFunctionDesc procedure (FR_Class unit): //使用frAddFunctionDesc函數 frAddFunctionDesc(FuncLib, 'SUMTOSTR', 'My functions', 'SUMTOSTR(<Number>)/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 function library).//FuncLib是注冊的函數庫,如果沒有置為nil; 'SUMTOSTR' 是函數名稱,字符類型;'My functions' 是自定義函數种類,字符類型,自己指定;最后是描述信息. When function library is unregistered, all its function will be automatically removed from function list.//如果函數庫沒有注冊,調用函數時,函數會自動從函數列表移除.2. 第二個問題: [Query1.DataSetName."Field"] + [Query2.DataSetName."Field"]
3. Q: How I can transfer data to the report? // 傳送數据到報表 A: There is several methods to do this. First is to use global object frVariables (defined in FR_Class unit): //一种方法是使用全局對象 frVariables frVariables['My variable'] := 10; This code creates new variable with 'My variable' name and value = 10. //上面的代碼創建一個名為'My variable'的新變量,值為10. This method is best to transfer static data to the report. //此方法适合靜態數据. Second method is to use TfrReport.OnGetValue event. You can use this method to transfer dynamic data, i.e. data which changes from record to record. //第二种是用TfrReport.OnGetValue事件.可傳送動態數据. procedure TForm1.frReport1GetValue(ParName: String; var ParValue: Variant); begin if ParName = 'MyField' then //'MyField'報表中變量名. ParValue := Table1MyField.Value; //程序种變量值 end;注: 以上來源于FR2.46 的FAQ. 我沒有親自使用過,僅做參考.
Q: How I can add my own function?
A: Use TfrReport.OnUserFunction event. Here is simple example: procedure TForm1.frReport1UserFunction(const Name: String;
p1, p2, p3: Variant; var val: Variant);
begin
if AnsiCompareText('SUMTOSTR', Name) = 0 then
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).
Q: Ok, but it works only for one TfrReport component. I want to use
my function everywhere (in all TfrReport components).
A: 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 TMyFunctionLibrary.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);
Q: How I can add my function to function list (in expression builder)?
A: Use frAddFunctionDesc procedure (FR_Class unit): frAddFunctionDesc(FuncLib, 'SUMTOSTR', 'My functions',
'SUMTOSTR(<Number>)/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 function library). When function library is unregistered, all its
function will be automatically removed from function list.2.
[Query1.DataSetName."Field"] + [Query2.DataSetName."Field"]
3.
Q: How I can transfer data to the report?
A: There is several methods to do this. First is to use global object
frVariables (defined in FR_Class unit): frVariables['My variable'] := 10; This code creates new variable with 'My variable' name and value = 10.
This method is best to transfer static data to the report. Second method is to use TfrReport.OnGetValue event. You can use this
method to transfer dynamic data, i.e. data which changes from record
to record. procedure TForm1.frReport1GetValue(ParName: String; var ParValue: Variant);
begin
if ParName = 'MyField' then
ParValue := Table1MyField.Value;
end; Finally, third method is to define variable from dictionary
programmatically (see previous question): with frReport1.Dictionary do
begin
Variables['MyVariable'] := 'CustomerData.Customers."CustNo"';
Variables['Another Variable'] := '10';
end;
Q: How I can add my own function? //怎樣加入自定義函數?
A: Use TfrReport.OnUserFunction event. Here is simple example:
//使用TfrReport的OnUserFunction事件處理過程.例:
procedure TForm1.frReport1UserFunction(const Name: String;
p1, p2, p3: Variant; var val: Variant);
begin
if AnsiCompareText('SUMTOSTR', Name) = 0 then
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).//此后,即可在報表中任何地方使用SumToStr 函數(自定義)
Q: Ok, but it works only for one TfrReport component. I want to use
my function everywhere (in all TfrReport components).
//上面的做法只能在一個TfrReport組件中使用,如果在所有的TfrReport組件都可以使用應怎樣處理.
A: Make OnUserFunction event handler common for all components. If you
can't do this, you should create function library:
//使OnUserFunction 事件對所有組件共用,若不能實現,應該建立函數庫:
type
TMyFunctionLibrary = class(TfrFunctionLibrary)
public
constructor Create; override;
procedure DoFunction(FNo: Integer; p1, p2, p3: Variant;
var val: Variant); override;
end; constructor TMyFunctionLibrary.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);
Q: How I can add my function to function list (in expression builder)?//怎樣把自定義函數加入函數列表?
A: Use frAddFunctionDesc procedure (FR_Class unit):
//使用frAddFunctionDesc函數
frAddFunctionDesc(FuncLib, 'SUMTOSTR', 'My functions',
'SUMTOSTR(<Number>)/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 function library).//FuncLib是注冊的函數庫,如果沒有置為nil; 'SUMTOSTR' 是函數名稱,字符類型;'My functions' 是自定義函數种類,字符類型,自己指定;最后是描述信息. When function library is unregistered, all its
function will be automatically removed from function list.//如果函數庫沒有注冊,調用函數時,函數會自動從函數列表移除.2. 第二個問題:
[Query1.DataSetName."Field"] + [Query2.DataSetName."Field"]
3.
Q: How I can transfer data to the report?
// 傳送數据到報表
A: There is several methods to do this. First is to use global object
frVariables (defined in FR_Class unit): //一种方法是使用全局對象 frVariables frVariables['My variable'] := 10; This code creates new variable with 'My variable' name and value = 10. //上面的代碼創建一個名為'My variable'的新變量,值為10.
This method is best to transfer static data to the report.
//此方法适合靜態數据.
Second method is to use TfrReport.OnGetValue event. You can use this
method to transfer dynamic data, i.e. data which changes from record
to record.
//第二种是用TfrReport.OnGetValue事件.可傳送動態數据.
procedure TForm1.frReport1GetValue(ParName: String; var ParValue: Variant);
begin
if ParName = 'MyField' then //'MyField'報表中變量名.
ParValue := Table1MyField.Value; //程序种變量值
end;注: 以上來源于FR2.46 的FAQ.
我沒有親自使用過,僅做參考.