Donovan wrote:
> a) 1. -- Is setting System.IsMultiThread correct?? In essence the
> Delphi app
> just has one main thread?? It is the DLL that is creating the aditional
> threads and these are just calling back into the Delphi code
All IsMultiThread really does is serialise the memory manager which means
dynamic memory allocations are threadsafe which allows string handling to
work i.e. your IntToStr above which would have been accessing the heap to
return the result string.
> b) 2. -- Is the VCL thread safe?? If indeed we are in a multi-threaded
> situation as far as Delphi is concerned then if we say create a
> TCanvas as a
> local variable in the callback would that be causing an issue?? If we are
> multithreaded as far as Delphi is concerned, just how would we go about
> updating that TEdit on another form??
The VCL is not threadsafe. In general, don't attempt to directly 'drive'
your UI from a background thread. Use a TThread and Synchronise so that any
changes are done in the context of the main UI thread.
While Delphi does go to a fair bit of trouble to protect the Windows GDI
state from multiple threads with the Canvas, Pen, Brush, etc. Locks that
doesn't really help the basic VCL classes (and their various properties)
themselves, rather it just prevents Windows GDI state from getting totally
hosed. Delphi implicitly grabs the Canvas Lock as part of WMPaint for you
which is all nice and dandy provided you only try to party with the GDI
during Paint method.
Trying to paint directly via a Canvas in your Callback is probably going to
get messy since you are trying to Paint outside WMPaint time. You could
probably muck about with Canvas.Lock stuff (or TryLock) and only try to
party with the GDI when nothing else is but I would avoid it myself since it
probably doesn't gain you all that much in terms of UI responsiveness and
would be mighty hard to debug if any race-conditions arise.
Executive summary:
IsMultiThread is not enough but is necessary. Use TThread.Synchronise to
update your UI (i.e. TEdit.Caption) and let the normal message loop WMPaint
handle the Canvas update.
TTFN,
Paul.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz