Why don't my functions appear in the FastReport function tab?

2.4k Views Asked by At

I am trying to implement some functions in an external unit and call them inside the FastReport script. My unit is properly compiled, but the problem is no function or procedure appears in the functions tab. Can anybody advise how to sort this out? I am not sure if I missed something.

Below is an example of my unit code. The FastReport developer's guide states that the implementation should be like so.

unit frxCustomFuncs;

interface
var myGlobalVar: primitiveType;
implementation

uses sysUtils, Classes, fs_iinterpreter,
myUnit;

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;



procedure myCustomProcedure(myParam1, myParam2: TdateTime);
var myVar: TMyCustomClass; //declared in myUnit
begin
   myVar:= TMyCustomClass.create(myParam1, myParam2);
   try

Some code ...
        myGlobalVar:= myVar.property;
some code ...
   finally
     myVar.Free;
   end;
end;

{ TFunctions }

function TFunctions.CallMethod(Instance: TObject; ClassType: TClass;
  const MethodName: String; var Params: Variant): Variant;
begin
  if MethodName = 'myCustomProcedure' then
  myCustomProcedure(Params[0], Params[1]);
end;

constructor TFunctions.Create(AScript: TfsScript);
begin
  inherited create(AScript);
  with AScript do
  begin
      AddMethod('procedure myCustomProcedure(myParam1, myParam2: TdateTime)',
      CallMethod, 'My Functions', 'custom description');
  end;
end;

initialization
  fsRTTIModules.Add(TFunctions);

end.
1

There are 1 best solutions below

1
On

My guess: That unit lives in your own project and you're using the report designer in the IDE. The Designer in the IDE doesn't know, and shouldn't know, a thing about your current project.

Add the file to a design time package and the Designer in the IDE should pick up on those functions.