Hi all,
I know this may sound strange, but yes, it's 2009 and I need to write small application using BCB5 :)
The problem is that DynamicArray throws OutOfBound exception when trying to expand it from within worker thread.
I have global variable, let's say
DynamicArray<double> X;
In main thread I check the length of array and I get 0, which is OK (length wasn't set)
Application->MessageBox(itoa(X.Length,str , 10), "", MB_OK);
Below is my worker thread class
class ArrayModifierThread : public TThread
{
private:
DynamicArray<double> __thread X;
protected:
void __fastcall Execute();
public:
__fastcall ArrayModifierThread(bool CreateSuspended);
void setX(DynamicArray<double> &a);
};
So far so good. Next I create new thread:
ArrayModifierThread *t = new ArrayModifierThread(true);
t->setX(X); // Pass reference to my global DynamicArray
t->Resume();
Here the Execute() method gets executed:
void __fastcall ArrayModifierThread::Execute()
{
X.Length = 10;
X[5] = 45.5;
}
What I'd expect is that global array is expanded and 6th element gets value of 45.5.
But closer investigation from within main thread gives Length = 0 and ArrayOfBounds Exception:
Application->MessageBox(itoa(__X.Length,str , 10), "", MB_OK);
Application->MessageBox(itoa(__X[5],str , 10), "", MB_OK);
Could anybody tell me what I've missed?