377 views
in System Integration by
Hello,

I am generating a EW class outside the EW Studio. Currently I have some objects representing a enumerator. For example 0 = monday, 1 = tuesday, ...

In der GUI the string for the current language must be displayed. For example: 0 = monday, Montag, lunes, ...

The string is created as an EW const string variable.

It is not possible to set 0 = Strings::monday, 1 = Strings::tuesday, because this name is just the EW const string variable name.

Therefore I need a reference to the save location, which is not possible, because this is created with source code generation. What I need, is a connection of the EW string name to the middle ware.

What I do not want is something like a switch case.  For example:  if ( 0 ) str = Strings::monday

Is there any way to address a EW constant from outside of the GUI?

- Jonas

1 Answer

+1 vote
by

Hello Jonas,

if I understand your application case, you want to access Embedded Wizard own strings from C code. Generally, Embedded Wizard generates native code (e.g. ANSI C), so accessing the generated members is possible from the outside of Embedded Wizard world. When doing this, however, you should be very careful. This is an advanced aspect we officially don't document nor recommend.

At first I would recommend you to implement the desired access operation in Embedded Wizard own Chora language and then analyze the resulting generated code. In case, the generated code is ANSI C, you will see that the access to the string is performed by the function EwLoadString() or EwGetVariantsOfString() depending on whether the string constant contains multiple language/style variants or just a single version.

Once you have understood the generated code, you should be able to copy the code and use it within your own implementation. When accessing the strings from outside of Embedded Wizard, please note the following 3 sections:

Be careful when exchanging strings

Don't retain nor modify objects or strings

Take care in multi-threading environments.

This means, you can access the strings from the native code and evaluate them. Modifying them is not allowed. Storing the string for later use (e.g. in a C variable) will cause unpredictable crashes. Similarly invoking the function EwLoadString() and EwGetVariantOfString() from a thread other than the GUI thread will crash the system sooner or later.

Best regards

Paul Banach

by
Hi Paul,

the mentioned method EwLoadString() is called with a defined const value: EwLoadString( &_Const001D ).

Therefore it is not possible to make any comparison to the original EW string name. Accessing string without knowing the addess is critical dangerous, because when changing the order of strings or something like that will result in false presentation.

For a better understanding of my problem: I created a ComboBox widget and I want to set the information of the widget from the device driver. This mechanism should work automatic. It should be possible to change the entries of the ComboBox at runtime. F.e. 0 = monday, 1 = tuesday, ... then pressing another button and the entries are 0 = january, 1 = february, ... something like that. Outside of EW I only have the name of the constants. Is it possible to reference only with the name of a constant to the underlying string? Or do I have to find a solution inside EW?

- Jonas
by

Hello Jonas,

names like _Const001D refer to lokal strings, which result from locally used string literals. When you add string constants to a unit, the name of the constant are used. For example EwGetVariantOfString( &ExampleConst2 )).

Best regards

Paul Banach

by

Ok. I will have a look at this functionality. Thank you.

I only found EwLoadString() and there only the _ConstXYZ names are used. For EwGetVariantsOfString() there was no result, because it is actually EwGetVariantOfString() - without s. Better you edit your first answer to prevent missunderstanding for other readers wink

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

...