I am just posting in the hopes that somenone can explain a problem I seem to be having with Turbo C++. My application basically has two forms (Form1 and Form2). Form1 is the main form and Form2 is created dynamically, as the result of a button click event, from Form1 with the following code:
TForm2 *Form2 = new TForm2(this);
Form2–>ShowModal();
Form2 is not included in the Auto_Create forms list under Project Options. Form2 accesses a thread object, derived from the TThread class, called Thread. A new instance of the thread is created with the following code:
Thread *Thread1 = new Thread(true);
This is set running following a button click event with the following code:
Thread1->Resume();
The thread updates the contents of a TMemo object named Memo1 located on Form2. The thread code looks somthing like this:
void __fastcall Thread::Execute()
{
Synchronize(&UpdateMemo)
}
//---------------------------------------------------------------------------
void __fastcall Thread::UpdateMemo(void);
{
Form2->Memo1->Lines->Add("Thread Running!");
}
//---------------------------------------------------------------------------
The UpdateMemo function is defined in the Thread header file as:
void __fastcall Thread::UpdateMemo(void);
For some reason this code generates an access violation and I can't figure out why. If I include Form2 in the Auto_Create forms list under Project Options the thread runs (without generating errors), but doesn't update Memo1!! If I compile Form2 on its own or include Form2 in the Auto_Create forms list under Project Options and display it using the code:
Form2–>ShowModal();
without creating it dynamically, the thread runs and updates Memo1 as it should. I am guessing therefore that the problem arises from the way that Form2 has been created. Any help would be much appreciated as I am really quite stumped!
Many thanks in advance.
Ben.