283 views
in GUI Development by

Hi ,

I am trying to access the string that is null  value .but I am unable to check with the following condition . On debugging it get the error as Bad Operand 

var string label = "";

native {

 struct data p;

    label  = EwNewStringAnsi(p.label);

}

if(label != null)/  if(label != "\0"){                                                  
text.String = label;
}

else  {

I want to retain the previous string 

}

I read the doc "'Be careful when exchanging strings'." and also support answer but still unable to find the solution

1 Answer

0 votes
by

Hello Pidea,

the test whether a string is null or not is relevant for native C code only as explained in Be careful when exchanging string. Therefore the following code will report Chora compiler error: "Bad operands combination in expression with the operator '!='. The given operator was used with illegal operands of type 'string' and 'null'.":

if ( label != null )    // <-- will report 'error'
  text.String = label;

The above implementation would be correct in native C code only. If you want to test in Chora whether a string is empty or not, simply compare the string with an empty string literal "". For example:

if ( label != "" )
  text.String = label;

Starting with Embedded Wizard 10.00 the explicit comparison with an empty string can be omitted. To test whether a string is empty or not, just evaluate the string itself within the condition. For example:

if ( label )
  text.String = label;

Also possible, but less efficient is the approach to query the length of the string by using its property length. If the string is empty, its length is 0. For example:

if ( label.length )
  text.String = label;

Best regards

Paul Banach

by
hi paul thanks for the reply .

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...