Finishing an RSS Reader - Getting files from a website
(Page 3 of 4 )
So our application will now let us view RSS links in a web browser. It will also let us view locally stored XML files in a list view. But we have not yet discussed how to get the RSS or XML file from a website. So let's get on with it.
In Delphi, open up form3 and add an idHTTP component from the Indy clients tab. Then rename the TEdit to "url." And put http:// in its Text property on the object inspector. Form3 should look something like this:

Double click on the button and add the following code:
procedure TForm3.btnURLClick(Sender: TObject);
var
FStream: TFileStream;
begin
FStream := TFileStream.Create('feed.xml', fmCreate);
try
IdHTTP1.Get(url.Text, FStream);
finally
FStream.Free;
form1.wb.Navigate(url.Text);
end;
close;
end;
Before downloading the file, we create a TStream object to store its content, as the code below demonstrates:
FStream := TFileStream.Create('feed.xml', fmCreate);
The filename does not have to be "feed.xml;" it can be anything you want. The next bit of code actually gets the file from the website:
IdHTTP1.Get(url.Text, FStream);
The content of the file on the Internet is written to the "feed.xml" file and stored on the local disk.
Next: Full code for the RSS reader >>
More Delphi-Kylix Articles
More By Jacques Noah