Page 1 of 1

Register a custom function in a report

Posted: Tue Sep 20, 2016 5:01 pm
by Enrique
Hello.

We have included a custom function directly in the report code:

Public Class Report

Inherits Stimulsoft.Report.StiReport

Public Sub New()
MyBase.New
Me.InitializeComponent
End Sub

Public Function EN(palabra As String, listaPalabras As list(Of String)) As Boolean
For Each key As String In listaPalabras
If palabra = key Then
Return (True)
Else
Return (False)
End If
Next
End Function

#Region "StiReport Designer generated code - do not modify"
#End Region 'StiReport Designer generated code - do not modify
End Class

Can we include and register this function in the functions dictionary of the report?. Can you provide to us a sample of how to do it?

Thank you.

Re: Register a custom function in a report

Posted: Tue Sep 20, 2016 9:17 pm
by Alex K.
Hello,

Please check the following code:

Code: Select all

Public Class MyFunction
    Private Const Category As String = "MyFuncCategory"

    Public Shared Function MyFunc(value As String) As String
        Return value.ToUpper()
    End Function

    Public Shared Sub RegisterFunctions()
        Dim ParamNames = New String(0) {}
        Dim ParamTypes = New Type(0) {}
        Dim ParamDescriptions = New String(0) {}

        ParamNames(0) = "value"
        ParamDescriptions(0) = "Descriptions"
        ParamTypes(0) = GetType(String)

        Stimulsoft.Report.Dictionary.StiFunctions.AddFunction(Category, "MyFunc", "MyFunc", "Description", GetType(MyFunction), GetType(String),
            "Return Description", ParamTypes, ParamNames, ParamDescriptions)
    End Sub
End Class
Thnak you.

Re: Register a custom function in a report

Posted: Wed Sep 21, 2016 10:06 am
by jserret
Hello,

I have the same problem, in a new report I copied your code and I get an error "referencedAssemblies" .

I attaching the Mrt and a screenshot of the error (Sorry the screenshot are in spanish)

Might you help me?

Thank you

Re: Register a custom function in a report

Posted: Wed Sep 21, 2016 2:15 pm
by Alex K.
Hello,

We have found the issue with adding a custom function when selected VB script language for the report.
The issue is fixed. Will be available in the next prerelease build.

At the current moment, you can use the several ways:
- add this code for adding function to your application, not in the designer's Code tab
- select CSharp script language (attached report ReportC.mrt)

Thank you.

Re: Register a custom function in a report

Posted: Wed Sep 21, 2016 2:51 pm
by Alex K.
Hello,

Also, please check the modified report with VB script.

Thank you.

Re: Register a custom function in a report

Posted: Wed Sep 21, 2016 3:33 pm
by jserret
Aleksey wrote:Hello,

We have found the issue with adding a custom function when selected VB script language for the report.
The issue is fixed. Will be available in the next prerelease build.

At the current moment, you can use the several ways:
- add this code for adding function to your application, not in the designer's Code tab
- select CSharp script language (attached report ReportC.mrt)

Thank you.
Thanks, We'll wait for this issue fixed in the next build.

Aleksey wrote:Hello,

Also, please check the modified report with VB script.

Thank you.
This example if it works, but I still can add the function to the dictionary, is not visible


Thanks for you help, and I hope that the next build work

Re: Register a custom function in a report

Posted: Wed Sep 21, 2016 8:22 pm
by Alex K.
Hello,

Yes. In the EndRender event, this function is removed.
Please check the next build.

Thank you.

Re: Register a custom function in a report

Posted: Wed Sep 26, 2018 1:49 pm
by lboers61
Hi Alex,

Starting from which version/build should this be solved?

Thanks for answering,
Leen

Re: Register a custom function in a report

Posted: Wed Sep 26, 2018 2:29 pm
by lboers61
Hi Alex,

Starting from which version/build should this be solved?

Thank you.

Re: Register a custom function in a report

Posted: Thu Sep 27, 2018 6:40 am
by Lech Kulikowski
Hello,

Starting from 2016.3

Thank you.