I'm opening a socket connection with TidTCPClient to a server. Server starts sending me tones of different XML Data. However ReadLn does not help me because I don't know where did the xml start & stops. So I decided to use Capture. This works correct. But as I read from the documentation capture also calling ReadLn, means it reads line by line. A 30~40 lines of XML takes 1~2 secs to read sometimes. So I need to read it faster. Can I use ReadStream or any other thing else which makes difference?
The code I'm using now:
procedure TfrmMain.ThreadRun(Sender: TIdThreadComponent);
var
FData: TStringList;
FMemory: TStringStream;
begin
if Client.Connected = False then Exit;
FData := TStringList.Create;
Client.IOHandler.Capture(FData, '', False);
FMemory := TStringStream.Create('',TEncoding.UTF8);
FMemory.WriteString(FData.Text);
CoInitialize(Nil);
QInsert.ParamByName('XMLData').LoadFromStream(FMemory,ftBlob);
QInsert.Execute;
CoUninitialize;
FMemory.Free;
FData.Free;
end;
As you can see I'm inserting XML data to a local table and this is done really quick, 15ms ~ 60ms depending on size of the XML, but getting data is really painful.
CoInitialize()
andCoUninitialize()
calls belong in theOnBeforeRun
andOnAfterRun
events ofTIdThreadComponent
, not in theOnRun
event. – Remy Lebeau