Customer function in version 3.20

detlefdetlef Germany
edited 7:18PM in FastReport 3.0
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

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 7:18PM
    there is a change you need to modify your library
    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.
    ;)
  • Works ok to use those functions is frxReport. But how to use the same functions in a isolated script object (tFsScript), like this example:

    fsScript1.Clear;
    fsScript1.Lines := Memo.Lines;
    fsScript1.SyntaxType := LangCB.Items[LangCB.ItemIndex];
    fsScript1.Parent := fsGlobalUnit;

    How to add the same functions in fsGlobalUnit ?

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.