G'Day All,
This is the scenario:
1. Single Threaded Delphi App
2. External MS-C++ DLL
1. Single Threaded Delphi App
In order to generate some graphics the delphi app calls the DLL to do the
work and then gets called via a callback mechanism to draw some stuff on a
drawing surface. So......
Delphi interface unit for the DLL
//Type definition for callback procedure
type TOwnerDrawCallback = function (Handle : Integer; LayoutName : PChar;
ocbTime : Integer;
iRepeat : Integer; var pTargaDC : TARGADC; var pocbFX
:integer; var piEffect : integer;
var piRevealspeed : integer) : Integer; stdcall;
//Static method to register callback
function RegisterOwnerDrawCallback(Callback : TOwnerDrawCallback;
CallbackName : pChar) : Boolean; stdcall
//Delphi prototype for callback
function CallBack_StdAxis1(Handle : Integer; LayoutName : PChar; oCBTime :
integer; iRepeat : Integer;
var pTargaDC : TARGADC; var pocbFX :integer;
var piEffect : integer; var piRevealspeed :
integer) : Integer; stdcall;
So after we register the callback the following happens:
- Make call to start graphic rendering process
- DLL kicks off a thread to manage the callback using Win API CreateThread()
- DLL thread makes repeated callback calls to CallBack_StdAxis1 until
CallBack_StdAxis1 says it is done
Now we are running into a couple of problems here, and my understanding is a
bit fuzzy.....
- We were making repeated calls to IntToStr() and eventually the app was
dying and appeared to be dying inside IntToStr when IntToStr made a memory
allocation
1. Setting System.IsMultiThread := TRUE appears to have solved this problem
- We were accessing the VCL namely a TEdit.Caption on another form and this
was killing the app
2. If we had kicked off a sepearate thread ourselves via a TThread then we
would have had to use TThread.Syncronize to update the caption
So my questions are as follows
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
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??
TIA. Any pointers to additional reading would also not go amiss.....
------------------------------------------------------------------------
--Donovan
Donovan J. Edye [www.edye.wattle.id.au]
Namadgi Systems, Delphi Developer
Web: www.namsys.com.au E-Mail: [EMAIL PROTECTED]
Voice: +61 2 6285-3460 Fax: +61 2 6285-3459
TVisualBasic = Class(None);
------------------------------------------------------------------------
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz