Using a function declared in the application inside the report's script

Let's imagine you have a function in your application and you need to use it in a script inside a report. There are several options to do this. You can choose the most suitable one.

1) Create an object in the script and call its methods.

Create an object in your application:

namespace WindowsFormsApplication21
namespace WindowsFormsApplication21
    public class ObjectUsedInTheScript
        public void SomeFunc()
            System.Windows.Forms.MessageBox.Show("Some Function");

Then create this object from script in the report (for example Document.GenerateScript) and invoke its' method:

WindowsFormsApplication21.ObjectUsedInTheScript obj =
    new WindowsFormsApplication21.ObjectUsedInTheScript();

2) Use static method of an object

Create a static method of an object (Form1 for example) in the application and call it from the report's script:


3) Pass the object's reference to the report as a parameter and call a method of this object

Create a report parameter (call it “MyObj” for example) and access it from the script to invoke the method:

((WindowsFormsApplication21.ObjectUsedInTheScript) GetParameter("MyObj")).SomeFunc();

In order to pass an object as a parameter you need to subscribe to GetReportParameter event for ReportSlot:

inlineReportSlot1.GetReportParameter +=
    new PerpetuumSoft.Reporting.Components.GetReportParameterEventHandler(inlineReportSlot1_GetReportParameter);

Then you need to add your object as a report parameter:

void inlineReportSlot1_GetReportParameter
        (object sender, PerpetuumSoft.Reporting.Components.GetReportParameterEventArgs e)
      e.Parameters["MyObj"].Value = new UsedInTheScriptObject();
You can see an example of using a static function here:

Add Feedback