View Single Post
 
Old 09-12-2017, 04:09 PM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 173
Default

You really need to rethink your logic, this time remembering you are attempting to have a multi-threaded process.

In procedure ThreadEmail.Execute, you set up IdSMTP, Pool, SSHandler, the push the _Message_ onto your Queue, and then Free IdSMTP, SSHandler and shutdown Pool. Your TThreadItem apparently expects them to be available because you reference them. By the time TThreadItem.Execute gets around to using IdSMTP, it probably doesn't exist anymore, same for SSHandler and the Pool has been shutdown.

Also, You have multiple places you are outputting a message using MessageDlg in a try/except block. I'm sure you've heard, you cannot interact with the User Interface from within a thread. MessageDlg needs access to the main thread to display correctly.

Also, in TThreadItem.Execute, you do
_Message_.Free;
_Message_.Destroy;

Never call an Object's Destroy method. Free does that for you already.