我需要扫描驱动器以查找包含我的数据库文件的目录,以将它们添加到 BDE 路径。如何让我的代码使用线程更快地完成它?我使用的是delphi 2007,所以不支持omniThread。我需要知道如何制作线程,以及如何执行它。这是我的代码:谢谢。
procedure TMainFrm.RestoreDBDirs;
var
Lst: TStringList;
Dirs: string;
Counter, j, LstFrom, LstTo: integer;
SearchRec: TSearchRec;
ST: TScanThread;
begin
Screen.Cursor:= crHourGlass;
try
try
ChangeAlias(AliasCombo);//After this procedure the tables are closed
except
end;
Lst:= TStringList.Create;
Lst.Clear;
Counter:= 0;
if Assigned(ChooseDrvFrm) then
with ChooseDrvFrm do
begin
Lst.Add(lvDrives.Selected.Caption);
Dirs:= lvDrives.Selected.Caption;
Progress1.Position:= 0;
Progress1.Visible:= True;
stBar1.SimpleText:= 'Searching for Databases...';
end
else
begin
Lst.Add(GetSystemDrive);
Dirs:= GetSystemDrive;
end;
repeat
// Update Progress Bar
if Assigned(ChooseDrvFrm) then
with ChooseDrvFrm do
begin
Progress1.StepBy(1);
if Progress1.Position = Progress1.Max then
Progress1.Position:= 0;
end;
Dirs:= Lst.Strings[Counter] +'\';
if (Dirs <> '.') and (Dirs <> '..')then
if FindFirst(Dirs +'*.*', faDirectory, SearchRec) = 0 then
begin
if ((SearchRec.Attr and faDirectory) > 0)
and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
Lst.Add(Dirs + SearchRec.Name);
if Assigned(ChooseDrvFrm) then
ChooseDrvFrm.stBar1.SimpleText:= Dirs + SearchRec.Name;
end;
while FindNext(SearchRec) = 0 do
if ((SearchRec.Attr and faDirectory) > 0) and
(SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
Lst.Add(Dirs + SearchRec.Name);
if Assigned(ChooseDrvFrm) then
ChooseDrvFrm.stBar1.SimpleText:= Dirs + SearchRec.Name;
end;
end;
Counter:= Counter + 1;
FindClose(SearchRec);
until Counter = Lst.Count;
Dirs:= '';
if Assigned(ChooseDrvFrm) then
ChooseDrvFrm.Progress1.Position:= 0;
for Counter:= 0 to Lst.Count - 1 do
begin
if Assigned(ChooseDrvFrm) then
with ChooseDrvFrm do
begin
Progress1.StepBy(1);
if Progress1.Position = Progress1.Max then
Progress1.Position:= 0;
end;
if (FileExists(Lst.Strings[Counter] + '\Crt.DB'))
and (FileExists(Lst.Strings[Counter] + '\Ds.DB'))
and (FileExists(Lst.Strings[Counter] + '\Turim.DB'))
and (FileExists(Lst.Strings[Counter] + '\Rprt.DB'))
and (UpperCase(Lst.Strings[Counter]) <> UpperCase('C:\My Installations\Data'))
and (UpperCase(Lst.Strings[Counter]) <> UpperCase(ExtractFileDir(ParamStr(0)))) then
try
if Assigned(ChooseDrvFrm) then
ChooseDrvFrm.stBar1.SimpleText:= 'Restoring Databases: '+ Lst.Strings[Counter];
RestoreAlias(Lst.Strings[Counter]);
except
on EDatabaseError do;
end;
end;
if Assigned(ChooseDrvFrm) then
with ChooseDrvFrm do
begin
Progress1.Position:= 0;
Progress1.Visible:= False;
stBar1.SimpleText:= 'Done';
MessageDlg('Databases succesfully restored', mtInformation, [mbYes], 0);
Close;
end;
> FillAliasCombo; finally
> Lst.Free;
> Screen.Cursor:= crDefault; end;