你可以把这种文件当作是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)
)
}