Custom Function

I've added a function, that does show up on the report designer's function tab, in my new group 'SimpleLandlord Functions'
procedure TfraReportPicker.btnDesignClick(Sender: TObject);
begin
   frmReportViewer.frxReport.AddFunction('function fmtCur(c: Currency; IncludeCurrencySign: Boolean = True): String', 'SimpleLandord Functions');

  frmReportViewer.frxReport.DesignReport();
end;

On a field on the report changed the code in the OnBeforePrint Event to:
procedure frDsReportAmount1OnBeforePrint(Sender: TfrxComponent);
begin
       fmtCur(<frDsReport."Amount">, True);                                      
end;

On the form with the report component I changed the frxReportUserFunction to:
function TfrmReportViewer.frxReportUserFunction(const MethodName: string; var Params: Variant): Variant;
var
  c: Currency;
begin
  if (MethodName = 'fmtCur') then
  begin
    c      := Params[0];
    Result := fmtCur(c);
  end;
end;

But when I run the report I get the error:
---------------------------
Debugger Exception Notification
---------------------------
Project SimpleLandlord.exe raised exception class Exception with message 'Undeclared identifier: 'fmtCur''.
---------------------------
Break   Continue   Help   
---------------------------

Do you know what I have done wrong?




Comments

  • gpigpi
    edited 10:58AM
    if (MethodName = 'FMTCUR' {upper case required}) then
    
  • edited 10:58AM
    gpi wrote: »
    if (MethodName = 'FMTCUR' {upper case required}) then
    


    Thanks, I tried that, but I am not even hitting the function: (OnUserFunction)

    function TfrmReportViewer.frxReportUserFunction(const MethodName: string; var Params: Variant): Variant;

    I set a break point here and it never go to it.
  • gpigpi
    edited 10:58AM
    Did you assign TfrmReportViewer.frxReportUserFunction with frxReport.OnUserFunction event?
  • edited 10:58AM
    gpi wrote: »
    Did you assign TfrmReportViewer.frxReportUserFunction with frxReport.OnUserFunction event?

    in the OnUserFunction I have the code:
    function TfrmReportViewer.frxReportUserFunction(const MethodName: string; var Params: Variant): Variant;
    var
      c: Currency;
    begin
      if (MethodName = 'fmtCur') then
      begin
        c      := Params[0];
        Result := fmtCur(c);
      end;
    end;
    

    Is that what you mean?
  • gpigpi
    edited 10:58AM
    Create a small demo project with problem and attach it
  • edited 10:58AM
    gpi wrote: »
    Create a small demo project with problem and attach it
    Thank You, I solved that problem.
    In case anyone wanted to know the logic I was using did not go through the code to add the function.

    Sorry for the inconvenience.

Leave a Comment