242 views
in GUI Development by
When using the Text Editor Object, I am trying to limit my string to a fixed number of entered characters, As the characters are entered, I check to see if the TextEditor.String.length exceeds 5, and if so, perform the TextEditor.String.remove(0,1) to remove the left-most character in the string.  

Is there a way to assign this new "shortened" string back to the original "TextEditor.String"?  

If I try to enter a string using all of the same value but longer than my intended limit (e.g. '11111111') the function appears to get confused after doing the "remove" method, and allows the string to increase beyond 5 characters.

Thanks.

1 Answer

0 votes
by

Hello RichK,

depending on your application case you could:

Option 1: handle the limitation outside of the Text Editor component. For this purpose:

- add a slot method to the component containing the Text Editor.

- assign the slot method to the Editor's property OnChange.

- implement the slot method with following code lines (here to limit the number to 5 signs):

if ( TextEditor.String.length > 5 )
  TextEditor.String = TextEditor.String.remove( 0, 1 );

Option 2: Modify the Text Editor component to stop appending signs as soon as the desired number signs ahs been entered. 

- Open the Text Editor component for editing.

- Look for the slot method named onCharacterKey:

- Open the method for editing and add following two lines at its beginning (here to limit the number of signs to 8):

Generally, the Text Editor component is just a template. You can modify and enhance t according to your application case. You could, for example, enhance it by a new property named MaxLength. Then use this property in the if condition from the screenshot above. In this manner, you can configure each instance of the Text Editor with different parameters to limit the text length.

I hope it helps you further.

Best regards

Paul Banach

by
Paul,

Will option 1 work?  I saw that the support documents say "The method returns the new string without modifying the original string operand." and I was seeing some odd behavior and thought that maybe the original string was continuing to append the new characters even though I performed the "remove" function.

Rich
by
Hello Rich,

it works. Note the assignment operator =.

Best regards

Paul
by
Paul,

Regarding the memory allocated for the string in the Text Editor - when operations are performed on the string (such as the 'remove' method), the documentation states that the new string is returned, but the original string is untouched.  If I have a Text Editor object as part of one of my new classes, and I remove visibility of the Text Editor object once the text is accepted, and then make it visible again to perform operations if a new string is to be entered, am I in danger of creating a memory leak as more strings are created when I modify the initially-allocated string?

Thanks,

Rich
by

Hello Rich,

... am I in danger of creating a memory leak as more strings are created when I modify the initially-allocated string?

the memory management in Embedded Wizard is based on a garbage collection. It means, if new temporary strings are created as result of string operations, the temporarily used memory is automatically released during the next garbage collection cycle. There is no explicit 'free' nor 'delete' function. Only memory areas actively used in the application are retained. The garbage collection detects such dependencies automatically.

The garbage collection cycle runs usually at the end of each screen update. In case of an application producing a lot of garbage during the screen update (e.g. a loop creating many temporary strings), the system can be configured to run the garbage collection earlier (see also EW_USE_IMMEDIATE_GARBAGE_COLLECTION).

I hope it answers your question.

Best regards

Paul

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

...