Board index » delphi » TidHttp + XML data

TidHttp + XML data


2003-10-30 05:28:51 AM
delphi95
I have searched and searched and have not come up with any good examples of
what I need to do.
All I am trying to do is post an XML file to an ASP page. I have tried to
use the MSXML2.dll with no avail. I have imported this into Delphi and
created a type library. The following code works fine in an .exe
application but does not work in a .dll.
var
objDomDoc: ISMLDOMDocument;
xmlHttp: IServerXMLHTTPRequest;
begin
objDomDoc := coDOMDocument.Create;
xmlHttp := coServerXMLHTTP.Create;
objDomDoc.async := False;
objDomDoc.load('D:\SampleXMLFile.xml');
xmlHttp.Open('POST', HTTPSADDRESS, False,'','');
xmlHttp.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
xmlHttp.send(objDomDoc.xml);
end;
When running this code in a .dll, I get the error 'Project blah blah raised
exception class EOleSysError with Message 'CoInitialize' has not been
called.'
I am now trying to do the same thing using the Indy components. I can not
find any clear examples on how to perform this operation.
Any help with either method would be greatly appreciated.
Thanks
-Shaq
 
 

Re:TidHttp + XML data

Quote
var
objDomDoc: ISMLDOMDocument;
xmlHttp: IServerXMLHTTPRequest;
begin
objDomDoc := coDOMDocument.Create;
xmlHttp := coServerXMLHTTP.Create;

objDomDoc.async := False;
objDomDoc.load('D:\SampleXMLFile.xml');

xmlHttp.Open('POST', HTTPSADDRESS, False,'','');
XMLHttp.setRequestHeader('Content-Type', 'text/xml');
Quote
xmlHttp.send(objDomDoc.xml);
end;

When running this code in a .dll, I get the error 'Project blah blah raised
exception class EOleSysError with Message 'CoInitialize' has not been
called.'

I am now trying to do the same thing using the Indy components. I can not
find any clear examples on how to perform this operation.

Any help with either method would be greatly appreciated.
Make the change above...
 

Re:TidHttp + XML data

"Shaq" <XXXX@XXXXX.COM>writes
Quote
When running this code in a .dll, I get the error 'Project blah
blah raised exception class EOleSysError with Message
'CoInitialize' has not been called.'
The error is self explanatory - you did not call CoInitialize() for the
calling thread prior to instantiating the XML objects. MSXML is based on
COM, and all threads much call CoInitialize() before they can work with COM
objects.
Gambit
 

Re:TidHttp + XML data

It doesnt even get that far without the EOleSysError. I get the error when
I try to create the objDomDoc object.
-Shaq
"eshipman" <eshipman@yahoo!!!.com>writes
Quote
>var
>objDomDoc: ISMLDOMDocument;
>xmlHttp: IServerXMLHTTPRequest;
>begin
>objDomDoc := coDOMDocument.Create;
>xmlHttp := coServerXMLHTTP.Create;
>
>objDomDoc.async := False;
>objDomDoc.load('D:\SampleXMLFile.xml');
>
>xmlHttp.Open('POST', HTTPSADDRESS, False,'','');

XMLHttp.setRequestHeader('Content-Type', 'text/xml');

>xmlHttp.send(objDomDoc.xml);
>end;
>
>When running this code in a .dll, I get the error 'Project blah blah
raised
>exception class EOleSysError with Message 'CoInitialize' has not been
>called.'
>
>I am now trying to do the same thing using the Indy components. I can
not
>find any clear examples on how to perform this operation.
>
>Any help with either method would be greatly appreciated.

Make the change above...
 

Re:TidHttp + XML data

How do I call the CoInitialize/CoUniInitialize? Is there a website where I
can find this?
-Shaq
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Shaq" <XXXX@XXXXX.COM>writes
news:3fa0311c$XXXX@XXXXX.COM...

>When running this code in a .dll, I get the error 'Project blah
>blah raised exception class EOleSysError with Message
>'CoInitialize' has not been called.'

The error is self explanatory - you did not call CoInitialize() for the
calling thread prior to instantiating the XML objects. MSXML is based on
COM, and all threads much call CoInitialize() before they can work with
COM
objects.


Gambit


 

Re:TidHttp + XML data

"Shaq" <XXXX@XXXXX.COM>writes
Quote
How do I call the CoInitialize/CoUniInitialize? Is there a website where
I
can find this?
this method is in the ActiveX unit. Add that to your uses.
 

Re:TidHttp + XML data

"Shaq" <XXXX@XXXXX.COM>writes
Quote
All I am trying to do is post an XML file to an ASP page. I have tried to
use the MSXML2.dll with no avail. I have imported this into Delphi and
created a type library. The following code works fine in an .exe
application but does not work in a .dll.
Have you considered using OpenXML?
I succesfully use OpenXML combined with TidHTTP to post XML to my web
server. It works great.
OpenXML is a native Delpih XML solution. Its a set of components used for
manipulating XML. And it is FREE.
Download it here: www.philo.de/xml/
 

Re:TidHttp + XML data

"Shaq" <XXXX@XXXXX.COM>writes
Quote
How do I call the CoInitialize/CoUniInitialize?
Just call them. They are functions like any other. Unless your code is in
a thread of its own, where you can call them at the beginning/ending of the
thread, then just call them at the beginning/end of the particular function
instead, ie:
begin
CoInitialize(nil);
try
// do your work...
finally
CoUninitialize;
end;
end;
Gambit
 

Re:TidHttp + XML data

I added the ActiveX in the uses clause. And I was able to call the
CoInitialize/CoUninitialize without any errors.
Thanks for everyones help.
-Shaq
"Shaq" <XXXX@XXXXX.COM>writes
Quote
How do I call the CoInitialize/CoUniInitialize? Is there a website where
I
can find this?

-Shaq

"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>wrote in
message
news:XXXX@XXXXX.COM...
>
>"Shaq" <XXXX@XXXXX.COM>writes
>news:3fa0311c$XXXX@XXXXX.COM...
>
>>When running this code in a .dll, I get the error 'Project blah
>>blah raised exception class EOleSysError with Message
>>'CoInitialize' has not been called.'
>
>The error is self explanatory - you did not call CoInitialize() for the
>calling thread prior to instantiating the XML objects. MSXML is based
on
>COM, and all threads much call CoInitialize() before they can work with
COM
>objects.
>
>
>Gambit
>
>