I have an multithreaded application which runs fine, until I remove a procedure which is no longer needed. I am removing all the references to ADO (as I am no longer using ADO).
When I remove this procedure, any thread I have will not run. When the thread is executed, it will give the followinf error:
CoInitialize has not been called.
Here is the code, that creates the error when removed:
Here is the basic layout of one of my threads(they are all similar).
Declaration:
Start the thread
The actual thread execute:
------------------------------------
There's no place like 127.0.0.1
------------------------------------
When I remove this procedure, any thread I have will not run. When the thread is executed, it will give the followinf error:
CoInitialize has not been called.
Here is the code, that creates the error when removed:
Code:
procedure TfrmMain.SetADOObjects;
begin
ADOTableCustomers.ConnectionString := connString;
ADOTableCustomers.TableName := 'customer_msg';
ADOTableCustomers.Open;
end;
Here is the basic layout of one of my threads(they are all similar).
Declaration:
Code:
//type for updating items --> runs in it's own thread
type TUpdateItems = class(TThread)
protected
procedure Execute; override;
end;
Start the thread
Code:
procedure TfrmMain.cmdPerformOperationClick(Sender: TObject);
var
ItemThread : TUpdateItems;
begin
if optUpdateItems.Checked then
begin
intResult := MessageDlg('You are about to update the database with all item codes ' +
'from the Quicken database' + #13#10 + #13#10 +
'If you wish to update the Items codes and descriptions, click OK',
mtInformation, [mbOK, mbCancel], 0);
//user presses OK
if intResult = mrOK then
begin
//begin importing items and descriptions
ItemThread := TupdateItems.Create(True);
ItemThread.FreeOnTerminate := True;
ItemThread.Resume;
end
else
exit; //exit procedure
end;
end;
The actual thread execute:
Code:
//procedure to retrieve all items from the Quicken database
procedure TUpdateItems.Execute;
var
strTicket : WideString;
strXMLRequest, strXMLResponse : String;
//Create the RequestProcessor object
qbXMLCOM : TRequestProcessor2;
blnSessionBegun : Boolean; //utility variable
begin
frmMain.lblAdminErrorMsg.Caption := '';
Try //begin error trapping
//create new instance of TRrequestProcessor
qbXMLCOM := TRequestProcessor2.Create(nil);
qbXMLCOM.OpenConnection('','Update Database Inventory');
strTicket := qbXMLCOM.BeginSession('', QBXMLRP2Lib_TLB.qbFileOpenDoNotCare);
//session has begun
blnSessionBegun := True;
//show status label
frmMain.taStatus.Visible := True;
//assign strXMLRequestString to XML to update all items
strXMLRequest := '<?xml version="1.0" encoding="ISO-8859-1"?>' +
'<?qbxml version="AU3.0"?>' +
'<QBXML>' +
'<QBXMLMsgsRq onError="continueOnError">' +
'<ItemQueryRq requestID="1">' +
'</ItemQueryRq>' +
'</QBXMLMsgsRq>' +
'</QBXML>';
//parse XML to Quickbooks qbXML parser
strXMLResponse := qbXMLCOM.ProcessRequest(strTicket, strXMLRequest);
qbXMLCOM.EndSession(strTicket); //end session
qbXMLCOM.CloseConnection; //close connection
Except
on E : Exception do
begin
//close session and connection
if blnSessionBegun then
begin
qbXMLCOM.EndSession(strTicket);
qbXMLCOM.CloseConnection;
end;
frmMain.taStatus.Visible := False; //hide status label
frmMain.lblAdminErrorMsg.Caption := 'Error: ' + E.Message;
exit; //stop further processing
end;
end; {try}
frmMain.taStatus.Visible := False; //hide import label
//process XML datastream from Quickbooks
frmMain.SaveToXML(strXMLResponse, 'ItemUpdate.xml');
frmMain.FilterItems;
end;
------------------------------------
There's no place like 127.0.0.1
------------------------------------