Im trying to load a remotely hosted XML file using Delphi. I am assuming that I can load it from a Stream. I have a FetchRemote class that fetches the URL stream:
function TFetchRemote.StreamFromUrl(filename : String) : TMemoryStream;
var
memStream : TMemoryStream;
http : TIdHttp;
begin
http := TIdHttp.Create();
memStream := TMemoryStream.Create;
http.Get(url + filename, memStream);
Result := memStream;
end;
I am trying to use the returned memory stream to load the remote XML:
function TFetchRemoteXML.XMLFromUrl(filename : string) : TXMLDocument;
var
memStream : TMemoryStream;
begin
memStream := fetchRemote.StreamFromURL(filename);
try
memStream.Position := 0;
Result := TXMLDocument.LoadFromStream(memStream);
finally
memStream.Free;
end;
end;
The error that I am getting when I try compiling is: (On the Result return line)
[dcc32 Error] FetchRemoteXML.pas(31): E2076 This form of method call only allowed for class methods or constructor
I have a similar class/method to fetch a remote Bitmap and it works fine. I just can't see what I am doing wrong to fetch the XML. I have tried following some examples in the Delphi help, and tried getting some hints from this StackOverflow question but no luck. Any suggestions would be greatly appreciated, I'm new to Delphi (coming from a Ruby background). I am using RAD Studio XE 5.
Thanks in advance!