cancel
Showing results for 
Search instead for 
Did you mean: 

How to Instantiate a TouchGFX object dynamically?

amirparto
Associate II

Hi, I use TouchGFX in my HMI project, I want to create an instance of an object (ig. a button) in runtime (dynamically), so I could destroy it later and free it's allocation memory.

I tried create it in a method but it seems to have runtime error:

void Screen1View::create_button()
{
	touchgfx::Button button1;
	button1.setXY(0, 0);
	button1.setBitmaps(touchgfx::Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_ID), 
        touchgfx::Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_PRESSED_ID));
 
	add(button1);
 
	button1.invalidate();
}

0693W00000D1nskQAB.jpg 

Does anyone have any solution?

1 ACCEPTED SOLUTION

Accepted Solutions
scottSD
Lead

To my knowledge it can't be done. I asked about this a while back and i believe the answer has something to do with the way TouchGFX is configured.

You will need to place the declaration of that button in your class header file and it should work fine.

Here is @Martin KJELDSEN​  's explanation on this in the following thread:

https://community.st.com/s/question/0D50X0000AVS2tcSQD/is-it-possible-to-dynamically-add-guiobjects

View solution in original post

3 REPLIES 3
scottSD
Lead

To my knowledge it can't be done. I asked about this a while back and i believe the answer has something to do with the way TouchGFX is configured.

You will need to place the declaration of that button in your class header file and it should work fine.

Here is @Martin KJELDSEN​  's explanation on this in the following thread:

https://community.st.com/s/question/0D50X0000AVS2tcSQD/is-it-possible-to-dynamically-add-guiobjects

Thanks. It helped a lot.