Hi,
I have used a TThreadList to pass information between threads with other programs I have written. The TThreadList is thread safe so you can use it between threads. Declare the TThreadList in the implementation var section.
To pass messages between threads I create a message record type and then create a pointer to that type. You can then use the
New() to generate message records which can be passed between threads. When you lock a thread safe list you get a pointer to a TList which is a list of pointers. Use the list methods to pull messages on or off the list. Don't for get to use a
try finally block around the TThreadList.LockList function so if an exception occurs you can release the lock on the list , in the
finally section so as you don't block the other thread.
On the GUI side use a
TTimer to call a procedure to clean up any handled messages / collect data to display results from messages etc. I would also recommend that you don't try to pass pointers or objects in the messages belonging to other threads as this is asking for trouble. Use
Dispose() to free the memory associated with any messages you have finished with.
I hope this helps - Jack
type TEDITOR_COMMAND = (EM_HI);
type MDATA_TYPE = (D_COMMAND,D_STRING,D_INTEGER);
type REditorMessage = record
MESS:TEDITOR_COMMAND;
MHANDLE:Integer;
REPLY_TO:Pointer;
Handled:Boolean;
Case MDATA_TYPE of
D_COMMAND:();
D_STRING:(S:ShortString);
D_INTEGER:(I:integer);
end;
type PREditorMessage = ^REditorMessage;
Jack Taylor