Best Practices in Delphi

I am implementing a sync method inside my application. The main steps it will follow are as follows:

  • Retrieve XML content from a remote site
  • Parse this XML with IXMLDomDocument2
  • Updating the Firebird database

The logic is quite complex, but it works great on its own.

The problem is I am trying to run it on a separate thread. It's clear to me that I don't understand the correctness of the flow in my logic.

So let's cut it off

I - Get content using TidHTTP

I didn't have any problems with this, if I have any problems here?

II - for IXMLDomDocument2 I'm calling

CoInitializeEx(nil, 0);


which according to the documentation should be enough to safely use IXMLDomDocument2 . And everything seems to be in order, after adding it I didn't get any errors when trying to use it. Is there any additional concern?

III - Using Firebird Safely

My problems are here. Sometimes it works, sometimes it doesn't (I think this is the main symptom of poorly designed threading logic). Most of the time I get an EInterbaseError with the message "Error reading data from connection". In other cases, it simply blocks.

Do I need to have a separate database connection?


source to share

1 answer

Warren nailed the main problem by tying the connection between background and foreground thread ... you have another problem and every call to CoInitialize must be paired with CoUninitialize