一表有两个字段'名称','地址'.如何将IE5收藏夹中的站名和网址引入这个表中?初学请细讲(100分)

  • 主题发起人 主题发起人 milton
  • 开始时间 开始时间
“收藏夹” 即 你的C:/WINDOWS/Favorites 中的内容。

如我的“收藏夹”中有“Sohu”

Sohu.url中的内容:

[DEFAULT]
BASEURL=http://www.sohu.com/

[DOC#17]
BASEURL=http://netads.sohu.com/html.ng/Params.richmedia=yes&Site=SOHU&Channel=frontpage

[InternetShortcut]
URL=http://www.sohu.com/
Modified=80B7853D42F2BF01ED

从上面可知:
'名称': sohu (文件名)
'地址' URL=http://www.sohu.com/


 
你可以把这种文件当作是ini文件来读取
这样的话,读的时候就简单多了。

unit MainPas;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,inifiles, DBTables, Db, ExtCtrls, DBCtrls, Grids, DBGrids,
Buttons;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
ListBox1: TListBox;
Label1: TLabel;
Button3: TButton;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
Table1Name: TStringField;
Table1URL: TStringField;
Query1: TQuery;
DataSource2: TDataSource;
Panel1: TPanel;
DBNavigator1: TDBNavigator;
Button4: TButton;
BitBtn1: TBitBtn;
Refresh: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Panel1DblClick(Sender: TObject);
procedure RefreshClick(Sender: TObject);
private
procedure FindAllURLFiles;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

var
FavoritesPath : String;
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
URLIniFile : TIniFile;
begin


URLIniFile := TIniFile.Create(FavoritesPath+'上海计算机报社.url');
edit1.text := URLIniFile.ReadString('InternetShortcut', 'URL', 'Error');
URLIniFile.Free;

end;

procedure TForm1.FindAllURLFiles;
var
Found : Integer;
SearchRec : TSearchRec;
begin
Found := FindFirst(FavoritesPath+'*.URL',faAnyFile,SearchRec);
while Found = 0 do
begin
ListBox1.Items.Add(SearchRec.Name);
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
FindAllURLFiles;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Query1.ExecSQL;
Query1.Close;

Table1.Refresh;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
I : Integer;
URLIniFile : TIniFile;
begin
for I := 0 to ListBox1.Items.Count-1 do
begin
Table1.Append;
Table1Name.Value := ListBox1.Items;

URLIniFile := TIniFile.Create(FavoritesPath+ListBox1.Items);
Table1URL.Value := URLIniFile.ReadString('InternetShortcut', 'URL', 'Error');
URLIniFile.Free;

Table1.Refresh;
end;

Table1.First;

end;



procedure TForm1.FormShow(Sender: TObject);
var
pc_WindowsPath : PChar;
NowPath : String;
begin
GetDir(0,NowPath);
Table1.DatabaseName := NowPath;
Query1.DatabaseName := NowPath;

Table1.Open;

GetMem(pc_WindowsPath,MAX_PATH);
GetWindowsDirectory(pc_WindowsPath,MAX_PATH);
Edit1.Text := pc_WindowsPath+'/Favorites/';
FavoritesPath := Edit1.Text ;

FindAllURLFiles;

Button3Click(Sender);

end;

procedure TForm1.Panel1DblClick(Sender: TObject);
begin
Button4.Visible := True;
Refresh.Visible := True;
end;

procedure TForm1.RefreshClick(Sender: TObject);
begin
FindAllURLFiles;

Button3Click(Sender);

end;

end.

{
CREATE TABLE Favorites(
NAME char(255),
URL char(255)
)
}
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部