Event react change variable

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Event react change variable

Post by mxoliveira73 » Thu May 23, 2019 3:28 am

is it possible create events that reacts to change of variable int?

Problem: I have other part of program, that change numbers of one variable "int num".
Can I create one event that react to this change?

For example, if int num = 1, position of StaticText1 is 10,10;
if int num =2, position of StaticText1 is 20,10
if int num = 3, position of Statictext1 is 30,10.

The int num change many and many times, coming from other part of software...
If yes, can you have me some tips?

User avatar
doublemax
Moderator
Moderator
Posts: 14892
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Event react change variable

Post by doublemax » Thu May 23, 2019 5:03 am

Problem: I have other part of program, that change numbers of one variable "int num".
Can I create one event that react to this change?
There is no event for that.

You should replace all locations where you change the variable with a method call. Then inside the method, you can set the variable and also change the static text.

The only way to do what you want, would be to have a timer that regularly checks the value of the variable and updates the static text when it has changed.
Use the source, Luke!

Kvaz1r
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 212
Joined: Tue Jun 07, 2016 1:07 pm

Re: Event react change variable

Post by Kvaz1r » Thu May 23, 2019 7:14 am

There is also observable pattern, so you also can use some useful libraries like this one:
observable

Btw, I don't think it's a good idea create many topics for one question(How to acces property of object in function outside of the Frame? and I need modify a property in other window). If you didn't get understandable explanation ask about hard parts or rephrase question or provide SSCCE.

Post Reply