User Function not working after showing Designer

Hi there,

I find that the user defined function I create no longer works after showing Report Designer

Here is what I did :
1. Add my function:

begin
frxReport1.AddFunction( 'Procedure MyFunction' );
frxReport1.OnUserFunction := MyFunction;
end;

function TForm2.MyFunction(const MethodName: string; var Params: Variant): Variant;
begin
showmessage('Hello World');
end;

2. Put the function on Report Memo DoubleClick event Script:

procedure Memo1OnPreviewDblClick(...)
begin
MyFunction;
end;

3. Compile and run the program (when I double click the memo here, it works)
4. Show the designer:

frxReport1.DesignReport

5. Close the Designer

6. When I double click the Memo, the user function does not work


If I run "frxReport1.ShowReport;" after returning from Designer, it works.. but I don't want that since the Report takes sometime to load

Can Anyone help me, did I do something wrong


Thanks

Comments

  • edited 3:09AM
    Try this:
      begin
        frxReport1.AddFunction( 'Procedure MyFunction' );
        frxReport1.OnUserFunction := frxReport1UserFunction; 
      end;
    
      function TForm2.frxReport1UserFunction(const MethodName: string; var Params: Variant): Variant;
      begin
        Result := -1;
        if (MethodName = 'MyFunction') then
        begin
          showmessage('Hello World');
          Result := 0;
        end;
      end;
    
  • edited 3:09AM
    madas wrote: »
    Try this:
      begin
        frxReport1.AddFunction( 'Procedure MyFunction' );
        frxReport1.OnUserFunction := frxReport1UserFunction; 
      end;
    
      function TForm2.frxReport1UserFunction(const MethodName: string; var Params: Variant): Variant;
      begin
        Result := -1;
        if (MethodName = 'MyFunction') then
        begin
          showmessage('Hello World');
          Result := 0;
        end;
      end;
    

    Thanks Madas
    I see you add a MethodName check and a Result value

    I tried your suggestion but I'm afraid it is still not working.

    Do you have any other Idea ?
  • edited 3:09AM
    I still need help on this problem, could any one give me some advise ?

    is this a fast report bug ?
  • edited 3:09AM
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, frxClass, frxDesgn;
    
    type
      TForm1 = class(TForm)
        frxReport1: TfrxReport;
        Button1: TButton;
        Button2: TButton;
        frxDesigner1: TfrxDesigner;
        procedure FormShow(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        function frxReport1UserFunction(const MethodName: String;
          var Params: Variant): Variant;
      private
        { Private-Deklarationen }
      public
        { Public-Deklarationen }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormShow(Sender: TObject);
    begin
      frxReport1.ReportOptions.Name := 'Testreport';
      frxReport1.LoadFromFile('D:\test.fr3');
      frxReport1.AddFunction('function MyFunction: Integer', 'User Function','');
      if not frxReport1.PrepareReport then
      begin
        Sleep(250);
        Application.ProcessMessages;
        if not frxReport1.PrepareReport then
          raise Exception.Create('Druckdokument konnte nicht geladen werden!');
      end;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      frxReport1.DesignReport;
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      frxReport1.ShowReport();
    end;
    
    function TForm1.frxReport1UserFunction(const MethodName: String; var Params: Variant): Variant;
    begin
      Result := -1;
      if (MethodName = 'MYFUNCTION') then
      begin
        ShowMessage('Test');
        Result := 0;
      end;
    end;
    
    end.
    

    once more. try this. [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> i think the user function must be real function and not a procedure. if the user fucntion is a procedure you cant drag this "function" on to the report within the designer. greetings.[/img]
  • edited 3:09AM
    Thanks Madas,

    I'm using a TfrxPreview to Show the report.

    it is on the TfrxPreview that the UserFunction does not work after showing Designer.


    Sorry I didn't mention this, I didn't know that a report can be shown without a preview [img]style_emoticons/<#EMO_DIR#>/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> PS : the UserFunction will work if after I close the designer, I call "frxReport1.ShowReport();" The question is that I would like to skip "frxReport1.ShowReport();" because re-loading the report take sometime.[/img]

Leave a Comment