Delphi 7: Threading
Posted on 2006-10-27
I have a couple of threading related questions:
I have an email client application in development.
The Send and Receive process are coded in a Thread using Win API.
Example: " ThreadHandle := CreateThread(nil, 0, @CheckNewMessagesThread, Pointer(AccountID), 0, ThreadID);"
When running this Thread and simaltaneously clicking on the MainForm's TreeView nodes the app hangs.
I know that my Thread might not be safe but I would like to get clarity on what I can AND what I CANT do.
On the Treeviews.OnChange event I make calls to Procedures that are also referenced in my Thread. (Problem, right?).
In my thread:
1. Can I make calls to other procedures and functions that the Application also uses?
In the Thread I make a call to "Procedure TestProcedure()". How can I safely make a call to the very same
Procedure from within my application and or Thread?
2. Regarding database.
I am using TIBQuery and TIBTransactions in my application.
The Procedure mentioned above uses a TIBQuery and TIBTransaction component?
Is it safe? If not how to work around then?
3. Is there any advantage to create component dynamically (run time) used in Procedures that are been called from
within the Thread and also the Main application? Does this have any advantage above creating components design
time for example: WIth TIBQuery and TIBTransaction? And also any component(s) in general.
4. Creating a Thread using Win API, how can I safely update components on forms. For example: To show the progress
of the thread I need to update a TLabel, TStatusBar.Panels.Text etc.... How to do this safely from within a Win API
5. And some might suggest me to use Delphi's TThread class. Ok, but I would like to see if it is possible using Win API CreateThread(). If not possible at all the please explain all the above using TThread class.
BTW: Can anyone suggest a great book focus mainly on Delphi Threading from beginning to end.
Willing to purchase if the books is really great and focusses on Threading.
Free e-books and tutorials which are good will also be appreciated.
Please help as if I am total beginner.