I still have trouble with Custom Functions
Sorry to return to this question, but I do not see what I'm doing wrong.
I followed the Developer manual, pages 43-45:
1- "If you wish to connect (add) a large number of functions, it is recommended to placet all logic in a separate library unit. Here is an example:"
2 -" Save the file with a .pas extension then add a reference to it in the uses clause of
your Delphi project???s form and all your custom functions will be available for use in any
report component. No need to write code to add these functions to each ???TfrxReport???, and
no need to write additional code for each report component???s ???onuserfunction ??? handler."
This simply does not happen!!!
When I open any report, the custom function does not appear in the function tree.
My reports are in a Data Module.
My Delphi version is XE2 e FR version is 4.12.
Thanks and sorry for my English.
I followed the Developer manual, pages 43-45:
1- "If you wish to connect (add) a large number of functions, it is recommended to placet all logic in a separate library unit. Here is an example:"
unit FastReportFunctions;
interface
implementation
uses SysUtils, Classes, fs_iinterpreter;
type
TFastReportFunction = class(TfsRTTIModule)
private
function CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String; var Params: Variant): Variant;
public
constructor Create(AScript: TfsScript); override;
end;
function FRFileExist(aFile: String): Boolean;
begin
if (FileExists(aFile)) then
Result:= True
else
Result:= False;
end;
{ TFastReportFunction }
constructor TFastReportFunction.Create;
begin
inherited Create(AScript);
AScript.AddMethod('function FRFileExist(aFile: String): Boolean;', CallMethod, 'My functions', ' Verifica se existe o arquivo');
end;
function TFastReportFunction.CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String; var Params: Variant): Variant;
begin
if MethodName = 'FRFILEEXIST' then
Result := FRFileExist(Params[0]);
end;
initialization
fsRTTIModules.Add(TFastReportFunction);
end.
2 -" Save the file with a .pas extension then add a reference to it in the uses clause of
your Delphi project???s form and all your custom functions will be available for use in any
report component. No need to write code to add these functions to each ???TfrxReport???, and
no need to write additional code for each report component???s ???onuserfunction ??? handler."
This simply does not happen!!!
When I open any report, the custom function does not appear in the function tree.
My reports are in a Data Module.
My Delphi version is XE2 e FR version is 4.12.
Thanks and sorry for my English.
Comments
I managed to solve with your help, and want to share with everyone:
I added a new project and created a Package.
In the package insert unit with the custom functions of Fast Report.
Next compile and install the package.
The function appears in Fast Report.
But I do not know why, she's doubled.