Skip to Content

Incompatible type for NOT operator: nullable`1[system.boolean].

Hello, all

I am having a strange problem in consuming my PB.NET assebly in another PB.NET application.

I have a function InitializeComponent in the assebly, which returns boolean,

But when I try to use it in the following code:

//---------------------------

if not ln_guest_srv.InitializeComponent(gs_odbc) then

return false

end if

//-------------------------

I get the following error:

Incompatible type for NOT operator: nullable`1[system.boolean].

Is there some definition problem in the assembly?

Arcady

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 02, 2014 at 09:26 PM

    If it's returning a nullable boolean you should be able to access the non-null value through the data types value property:

    if not ln_guest_srv.InitializeComponent(gs_odbc).Value then

    return false

    end if

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 02, 2014 at 12:55 PM

    Hi Arcady.

    Can you return System.Boolean instead of Boolean? Unless null has some significance to you it should be ok to do this. I generally only define values as nullable if they are coming from the db.

    Hth,

    Mark

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Arcady Abramov

      Also, make sure every code path in your method returns a value... If the default return is false, make sure to have a RETURN FALSE right at the end.

      If I was creating a PB to C# converter, I would make this method return a nullable type:

      FUNCTION BOOLEAN InitializeComponent(string as_odbc)

      IF as_odbc = "valueA" THEN

      RETURN TRUE

      END IF

      IF as_odbc = "valueB" THEN

      RETURN FALSE

      END IF

      END FUNCTION

  • author's profile photo Former Member
    Former Member
    Posted on Jun 01, 2014 at 08:00 PM

    Hi.

    What does the InitializeComponent? Are you sure it runs correctly? Gs_odbc has a value? Are all used objects valid when required? I would try to step-in to see if everything workd fine...

    Andreas.

    Add a comment
    10|10000 characters needed characters exceeded

    • The error comes at compile time, not in runtime.

      This particular function is, somewhat complicated. It is defined in the ancestor class of the service and, then, overriden in the descendent class, also using super::initializeComponent(string gs_odbc) function call.

      My question can be summed in the following way:

      How can a PB Boolean function become nullable`System.Boolean in .NET compilation?

      This is important for my future development, since this particular case has easily been worked around by using toString().ToLower() == "false" condition instead of a simple NOT.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.