RW-
Thanks for taking a look. I'm using the TThread class to try to help me.
If I use Synchronize() the graphics on the TForm are updated correctly as
the simulation "solve" method makes progress. However, I am prevented from
interacting with the TForm (e.g. I can't grab the title bar with the mouse
and move the window, or click any of the buttons on the TForm). It seems to
behave as if it is a single thread.
If I choose not to use Synchronize(), I am able to move the window about
while the "solve" method is running but the graphics are fouled up, and I
frequently encounter access violations.
Quote
There's an example also int the Examples folder of BCB.
The BCB example for threads with the sorting comparisons you pointed me to
does exactly what I want. I can move the window around while it's updating
the graphics in each of the three panels with no problems or surprises. It
appears to be very robust. The only difference that I can see between the
structure of that example and my code is that I am not painting directly to
the vcl component within the method passed to Synchronize(). The graphics
are updated several classes away using VTK methods. Also I create a
suspended thread, pass some pointers to the thread, and Resume() it.
My thread class is simple, so I included it below. I appreciate any further
insight you can give. It may be a VTK thread-safe issue.
Thanks again -
TH
// FILE: ThreadSolve.h
//--------------------------------------------------------------------------
-
#ifndef ThreadSolveH
#define ThreadSolveH
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include "Simulation.h"
#include <ComCtrls.hpp>
//--------------------------------------------------------------------------
-
class ThreadSolve : public TThread
{
private:
protected:
void __fastcall Execute();
Simulation *sim;
TStatusBar *statusBar;
public:
__fastcall ThreadSolve(bool CreateSuspended);
void setSimulation(Simulation *s,TStatusBar *sb);
void __fastcall stepSimulation(void);
};
//--------------------------------------------------------------------------
-
#endif
// FILE: ThreadSolve.cpp
//--------------------------------------------------------------------------
-
#include <vcl.h>
#pragma hdrstop
//--------------------------------------------------------------------------
-
#include "ThreadSolve.h"
#include "Simulation.h"
//--------------------------------------------------------------------------
-
__fastcall ThreadSolve::ThreadSolve(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//--------------------------------------------------------------------------
-
void ThreadSolve::setSimulation(Simulation *s,TStatusBar *sb){
this->sim = s;
this->statusBar = sb;
}
//--------------------------------------------------------------------------
-
void __fastcall ThreadSolve::Execute()
{
Synchronize(this->stepSimulation);
// this->stepSimulation(); <--------- ERRORS
}
//--------------------------------------------------------------------------
-
void __fastcall ThreadSolve::stepSimulation()
{
this->statusBar->SimpleText = AnsiString("Solving...");
this->sim->solve(); // computes new positions and updates graphics
pipeline
this->statusBar->SimpleText = AnsiString("Solving : DONE !!!");
}
//--------------------------------------------------------------------------
-
#pragma package(smart_init)