unit WebFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, ExtCtrls, ComCtrls;
type
TWebForm =
class(TForm)
StatusBar: TStatusBar;
TreeView: TTreeView;
Splitter: TSplitter;
WebBrowser: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure TreeViewChange(Sender: TObject; Node: TTreeNode);
procedure TreeViewDblClick(Sender: TObject);
procedure TreeViewDeletion(Sender: TObject; Node: TTreeNode);
end;
var
WebForm: TWebForm;
implementation
{$R *.dfm}
uses
IniFiles;
type
TLink =
class
Name:
string;
Url:
string;
Comment:
string;
end;
function CreateLink(
const name,
url, comment:
string): TLink;
begin
Result := TLink.Create;
Result.
Name :=
name;
Result.Url :=
url;
Result.Comment := comment;
end;
function IsLink(node: TTreeNode): Boolean;
begin
Result := Assigned(node.Data);
end;
procedure LoadBookmarks(
const fn: TFileName; nodes: TTReeNodes);
var
iCat, iLink: Integer;
bm: TMemIniFile;
cats, links: TStrings;
catNode: TTreeNode;
linkName, linkUrl:
string;
begin
cats := TStringList.Create;
links := TStringList.Create;
bm := TMemIniFile.Create(fn);
try
bm.ReadSections(cats);
for iCat := 0
to Pred(cats.Count)
do
begin
catNode := nodes.AddChild(
nil, cats[iCat]);
bm.ReadSectionValues(cats[iCat], links);
for iLink := 0
to Pred(links.Count)
do
begin
linkName := links.Names[iLink];
linkUrl := links.ValueFromIndex[iLink];
nodes.AddChildObject( catNode, linkName, CreateLink( linkName, linkUrl, '
' ) );
end;
end;
finally
cats.Free;
links.Free;
bm.Free;
end;
end;
procedure TWebForm.FormCreate(Sender: TObject);
begin
LoadBookmarks(ChangeFileExt(ParamStr(0), '
.ini'), TreeView.Items);
end;
procedure TWebForm.TreeViewChange(Sender: TObject; Node: TTreeNode);
begin
if Assigned(Node)
and IsLink(Node)
then Statusbar.SimpleText := TLink(Node.Data).Url
else Statusbar.SimpleText := '
';
end;
procedure TWebForm.TreeViewDblClick(Sender: TObject);
var
Node: TTReeNode;
begin
with Sender
as TTreeView
do
Node := Selected;
if Assigned(Node)
and IsLink(Node)
then
with TLink(Node.Data)
do
WebBrowser.Navigate(
Url);
end;
procedure TWebForm.TreeViewDeletion(Sender: TObject; Node: TTreeNode);
begin
if IsLink(Node)
then
with TLink(Node.Data)
do Free;
end;
end.