cancel
Showing results for 
Search instead for 
Did you mean: 

Best method to exchange data between child container and parent container

Kevin(Dr.Electron)
Associate III

I have built a custom container (TextInput) where the user can enter a string of fixed length.

It is relatively similar in structure to the existing Keyboard Container

When the maximum string length is reached, a second custom container(TextValidation) becomes visible and shows the entire string, divided into several text boxes. If the user now clicks on a textbox, the TextValidation container should become invisible again and the substring should be available for modification in the TextInput window.

Currently I have a public method setText in the TextInput class, which calls setWildecard.

In the TextValidation container, after a button click, the getParent method is called, the drawable object is casted to a TextInput and from this the setText method is called.

I am relatively new to c++ and probably there are much better ways to solve this problem.

What is the recommend way to resolve this problem?

1 ACCEPTED SOLUTION

Accepted Solutions
Kevin(Dr.Electron)
Associate III

Hello Alexandre,

First, sorry for my late reply.

I learned about custom callbacks this weekend and they helped me a lot to return values from Containers. To pass values to a container I still use puplic methods.

This is the method, which i call when the user is finished inputing text. It makes the textValidation container visible. This container shows the input Text and asks to verify, that the user did type the correct text.

void Textnput::bOK_Clicked()
{
    if (BUFFER_SIZE == TEXTAREA_SIZE_3)
        Unicode::strncpy(textAreaBuffer+offset, textAreaBuffer_3, BUFFER_SIZE - 1);
    
    textValidation.setTextToValidate(textAreaBuffer);
    textValidation.setVisible(true);
    textValidation.invalidate();
}
void TextValidation::setTextToValidate(Unicode::UnicodeChar Text)
{
    Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%c%c%c", Text[0], Text[1], Text[2]);
    Unicode::snprintf(textArea2Buffer, TEXTAREA2_SIZE, "%c%c%c", Text[3], Text[4], Text[5]);
    Unicode::snprintf(textArea3Buffer, TEXTAREA3_SIZE, "%c%c%c", Text[6], Text[7], Text[8]);
    ...
    ...
}

After the user verified the Input, i execute the callback, which makes the textValidation container invisible.

I am now quite satisfied with this method. I actually only wanted to ask if this is the best option, since I have almost no experience with c++.

Kevin

View solution in original post

2 REPLIES 2
Alexandre RENOUX
Principal

Hello Kevin,

Could you provide some code in order to have a clearer view and to be able to give a relevant answer ?

You can add some code by clicking on the icon "</>" visible below when you are writing a comment.

/Alexandre

Kevin(Dr.Electron)
Associate III

Hello Alexandre,

First, sorry for my late reply.

I learned about custom callbacks this weekend and they helped me a lot to return values from Containers. To pass values to a container I still use puplic methods.

This is the method, which i call when the user is finished inputing text. It makes the textValidation container visible. This container shows the input Text and asks to verify, that the user did type the correct text.

void Textnput::bOK_Clicked()
{
    if (BUFFER_SIZE == TEXTAREA_SIZE_3)
        Unicode::strncpy(textAreaBuffer+offset, textAreaBuffer_3, BUFFER_SIZE - 1);
    
    textValidation.setTextToValidate(textAreaBuffer);
    textValidation.setVisible(true);
    textValidation.invalidate();
}
void TextValidation::setTextToValidate(Unicode::UnicodeChar Text)
{
    Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%c%c%c", Text[0], Text[1], Text[2]);
    Unicode::snprintf(textArea2Buffer, TEXTAREA2_SIZE, "%c%c%c", Text[3], Text[4], Text[5]);
    Unicode::snprintf(textArea3Buffer, TEXTAREA3_SIZE, "%c%c%c", Text[6], Text[7], Text[8]);
    ...
    ...
}

After the user verified the Input, i execute the callback, which makes the textValidation container invisible.

I am now quite satisfied with this method. I actually only wanted to ask if this is the best option, since I have almost no experience with c++.

Kevin