Customer function in version 3.20
detlef
Germany
I???m using a separate unit to add my own functions, like the example in the Developer's manual (fsGlobalUnit.AddMethod).
Since I???m using the version 3.20 I have a problem. The reports are shown correctly, since I added the following line to my program:
frxReport1.Script.Parent := fsGlobalUnit
But my functions are not showing up in the list of functions of the reportdesinger.
Please let me know, what I have to change and give me an example.
Regards
Detlef
Since I???m using the version 3.20 I have a problem. The reports are shown correctly, since I added the following line to my program:
frxReport1.Script.Parent := fsGlobalUnit
But my functions are not showing up in the list of functions of the reportdesinger.
Please let me know, what I have to change and give me an example.
Regards
Detlef
Comments
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 myfunctions;
interface
implementation
uses SysUtils, Classes, fs_iinterpreter; // you can also add a reference //to any other external library here
type
TFunctions = class(TfsRTTIModule)
private
function CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String; var Params: Variant): Variant;
public
constructor Create(AScript: TfsScript); override;
end;
function MyFunc(s: String; i: Integer): Boolean;
begin
// necessary logic
end;
procedure MyProc(s: String);
begin
// necessary logic
end;
{ TFunctions }
constructor TFunctions.Create;
begin
inherited Create(AScript);
with AScript do
AddMethod('function MyFunc(s: String; i: Integer): Boolean', CallMethod, 'My functions', ' MyFunc function always returns True');
AddMethod('procedure MyProc(s: String)', CallMethod, 'My functions', ' MyProc procedure does not do anything'');
end;
end;
function TFunctions.CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String; var Params: Variant): Variant;
begin
if MethodName = 'MYFUNC' then
Result := MyFunc(Params[0], Params[1])
else if MethodName = 'MYPROC' then
MyProc(Params[0]);
end;
initialization
fsRTTIModules.Add(TFunctions);
end.
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.
fsScript1.Clear;
fsScript1.Lines := Memo.Lines;
fsScript1.SyntaxType := LangCB.Items[LangCB.ItemIndex];
fsScript1.Parent := fsGlobalUnit;
How to add the same functions in fsGlobalUnit ?