When I have two forms (for example ‘FormMain’ and ‘FormSettings’) with the following code:
#include <Windows.h>
#include <string>
#include "FormMain.h"
#include "FormSettings.h"
using namespace std;
string someVariable = "";
void openFormSettings() {
FormSettings myForm;
myForm.ShowDialog();
}
I have opened ‘FormMain’ then I have opened the form ‘FormSettings’. How do I read and make changes in the variable ‘someVariable’ from the second form I opened? This is variable is used to hold some setttings of the main form which could be changed in the settings form.
This could be a stupid question but I’m a beginner to C++ …
OK, I think — without knowing lots of details — a possible strategy would be to construct the FormSettings so that it receives the FormMain as a reference (or a pointer), say you name it
formMain. Then you can callformMain.set_setting(blah);in the button callback of FormSettings.