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 6:36AM
    if (MethodName = 'FMTCUR' {upper case required}) then
    
  • edited 6:36AM
    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 6:36AM
    Did you assign TfrmReportViewer.frxReportUserFunction with frxReport.OnUserFunction event?
  • edited 6:36AM
    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 6:36AM
    Create a small demo project with problem and attach it
  • edited 6:36AM
    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

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.