Discussion:
Sending and receiving XML Data with idTCPServer
(too old to reply)
branden
2008-08-05 11:23:38 UTC
Permalink
 I am having major headaches with sending XML data from a client to a
server using Indy10 and the default XML parser in the internet pallette.

XML Data sent from idTCPClient via stream, this is fine.
XML Data received in idTCPServer and saves to a tMemorystream.
The problem I get is I cannot activate teh XML Component, I get an error
stating that the COInitialize has not been called.

This is a standard exe.

Research show I need to pu in the Coinitilize statement in the code but
i have no idea where nor how to.

Can you please help????

i will send sample code of both the server and client if needed



--- posted by geoForum on http://delphi.newswhat.com
Remy Lebeau (TeamB)
2008-08-05 18:26:04 UTC
Permalink
Post by branden
The problem I get is I cannot activate teh XML Component, I get
an error stating that the COInitialize has not been called.
The error is self-explanatory. You have not called CoInitialize/Ex() yet
before trying to instantiate the parser. The parser you are using is
internally trying to use an ActiveX object (if you are using TXMLDocument,
then on Windows machines it uses MSXML by default, which is ActiveX-based).
Any thread that wants to use an ActiveX object must call CoInitialize/Ex()
first. TIdTCPServer is a multi-threaded component.
Post by branden
Research show I need to pu in the Coinitilize statement in the code
but i have no idea where nor how to.
You can call it in the server's OnConnect event, and then call
CoUninitialize() in the OnDisconnect event.

A better way to do it would be to derive a new class from TIdThreadWithTask
and override its BeforeExecute() and AfterExecute() to make the calls
instead. Then assign one of the TIdSchedulerOfThread descendants (such as
TIdSchedulerOfThreadDefault) to the server's Scheduler property, and assign
your custom class type to the scheduler's ThreadClass property.


Gambit

Loading...