Question

I am making multiple windows forms in C++/CLI to run tests simultaneously, i can do this but i have variables defined inside my class as private but when the second form writes to its version of the variable it overwrites it for all the other forms version of this variable.

array<String^>^args = Environment::GetCommandLineArgs();
             int args1 = System::Convert::ToInt16(args[1]);
             int i;
             #pragma omp parallel for 
              for(i = 0; i < args1; i++)
              {
                Sleep(1000);
                Form1^ form1 = gcnew Form1(i);
                form1->Show();
              }



private ref class Form1 : public System::Windows::Forms::Form
{
private:
static int formnumber;
static SerialPort^ serialPort = gcnew SerialPort();
public:
    Form1(int formnum)
    {
        array<String^>^args = Environment::GetCommandLineArgs();
        formnumber = formnum;
        int a = 65;
        jigid = a + formnum;
        comnumber = formnumber + Convert::ToInt16(args[2]);
        InitializeComponent();
    }
}

when i create 2 forms formnum will always be 1 for later use in the forms beacuse the creation of the 2nd form overwrote formnum in the 1st form. how do i make it so that the forms cant overwrite each others variables?

Was it helpful?

Solution

Don't declare them static!........................

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top