Creating an RSS Reader - Code
(Page 2 of 4 )
Start a new application and add the following:
Component | Tab | Rename | Align |
Toolbar | Win32 | Toolbar1 | alTop |
TTreeview | Win32 | Tv1 | alLeft |
TSplitter | Additional | Splitter1 | alLeft |
TWebbrowser | Internet | wb | alClient |
StatusBar | Win32 | Statusbar1 | alBottom |
TSpeedButton | Additional | SpeedButton1 | auto |
TSpeedButton | Additional | SpeedButton2 | auto |
TSpeedButton | Additional | navBack | auto |
TSpeedButton | Additional | navForward | auto |
TSpeedButton | Additional | wbHome | auto |
TSpeedButton | Additional | wbStop | auto |
TSpeedButton | Additional | wbRefresh | auto |
You should have something like this:

Once all of the above is set, double click on the OnCreate event and add the following code:
procedure TForm1.FormCreate(Sender: TObject);
var
rec:TSearchRec;
SomeTxtFile : TextFile;
buffer : string;
begin
//read links from links file ***********************************
with tv1.Items.AddFirst( nil, 'RSS Links' ) do
begin
Selected := true;
end;
if fileexists('links.txt') then begin
AssignFile(SomeTxtFile, 'links.txt');
Reset(SomeTxtFile);
while not EOF(SomeTxtFile) do begin
ReadLn(SomeTxtFile, buffer);
with tv1.Items.AddChildFirst( tv1.Selected, buffer) do
begin
MakeVisible;
end;
end;
CloseFile(SomeTxtFile);
end //fileexists
else begin
with tv1.Items.AddFirst( nil, 'No RSS Links Found' ) do
begin
Selected := true;
end;
end ;
end;
The above code basically loads the RSS links from a textfile that is located on the local disk and adds them to the treeview. You can only view these links once you are connected to the Internet. Next, double click on the OnDblClick event of the treeview component and add the following code:
procedure TForm1.tv1DblClick(Sender: TObject);
begin
if (tv1.Selected.Level <> 0) then begin
fn:=tv1.Selected.Text;
form1.Caption:='';
//update the form caption
form1.Caption:='RSS XML File Reader - '+fn;
wb.Navigate(fn);
end;
end;
All that happens in the above code is that it basically navigates the selected RSS link to the WebBrowser component. The link name is captured in the "fn" variable and then the form caption is updated with it. Then the program gets the RSS data from the Internet link (stored in the fn variable) and displays the contents in the WebBrowser component
Next: Web Browser Code >>
More Delphi-Kylix Articles
More By Jacques Noah