Paulao
06-03-2012, 17:04:15
Quando hago una busca en un universo de unos 2.000 archivo(.pas y .dfm), se queda mui lenta mi aplicacion. Abajo mis codigos:
Mi procedure de busca
procedure TForm1.BuscaTexto(path: string; const FileMask, tipo, tabela: string);
var
SR: TSearchRec;
txt: TextFile;
Row: string;
Found: Boolean;
i: Integer;
NroExt: TStrings;
begin
NroExt:= TStringList.Create;
try
Varrer.Enabled := False;
NroExt.Delimiter:= ';';
NroExt.DelimitedText:= FileMask;
path := IncludeTrailingPathDelimiter(path);
for i:= 0 to NroExt.Count - 1 do
begin
if FindFirst(path + NroExt[i], faAnyFile - faDirectory, SR) = 0 then
repeat
Application.ProcessMessages;
AssignFile(txt,path + SR.Name);
Reset(txt);
Found:= False;
while not Eof(txt) and not Found do
begin
Readln(txt, Row);
if Pos(tabela, Row) > 0 then
begin
ListBox1.Items.Add(tipo + ';' + tabela + ';' + SR.Name);
Found:= True
end
end;
CloseFile(txt);
until FindNext(SR) <> 0
end;
finally
NroExt.Free;
Varrer.Enabled := True;
FindClose(SR);
end;
//end;
if FindFirst(Path + '*.*', faDirectory, SR) = 0 then
begin
try
repeat
if (SR.Name <> '.') and (SR.Name <> '..') then
TextFoundInFile(Path + SR.Name,'*.pas;*.dfm',tipo,tabela);
until FindNext(SR) <> 0;
finally
end;
end;
end;
Mi llamada a procedure
procedure TForm1.VarrerClick(Sender: TObject);
begin
ClientDataSet1.Open;
pth := IncludeTrailingPathDelimiter(edtDir.Directory);
while not ClientDataSet1.Eof do
begin
//TextFoundInFile(pth,'*.pas;*.dfm',ClientDataSet1.FieldByName('xtype').AsString,ClientDataSet1.FieldB yName('name').AsString);
BuscaTexto(pth,'*.pas;*.dfm',ClientDataSet1.FieldByName('xtype').AsString,ClientDataSet1.FieldByName ('name').AsString);
ClientDataSet1.Next;
end;
ListBox1.Items.SaveToFile(ExtractFilePath(Application.ExeName) + 'Fontes.csv');
end;
Mi procedure de busca
procedure TForm1.BuscaTexto(path: string; const FileMask, tipo, tabela: string);
var
SR: TSearchRec;
txt: TextFile;
Row: string;
Found: Boolean;
i: Integer;
NroExt: TStrings;
begin
NroExt:= TStringList.Create;
try
Varrer.Enabled := False;
NroExt.Delimiter:= ';';
NroExt.DelimitedText:= FileMask;
path := IncludeTrailingPathDelimiter(path);
for i:= 0 to NroExt.Count - 1 do
begin
if FindFirst(path + NroExt[i], faAnyFile - faDirectory, SR) = 0 then
repeat
Application.ProcessMessages;
AssignFile(txt,path + SR.Name);
Reset(txt);
Found:= False;
while not Eof(txt) and not Found do
begin
Readln(txt, Row);
if Pos(tabela, Row) > 0 then
begin
ListBox1.Items.Add(tipo + ';' + tabela + ';' + SR.Name);
Found:= True
end
end;
CloseFile(txt);
until FindNext(SR) <> 0
end;
finally
NroExt.Free;
Varrer.Enabled := True;
FindClose(SR);
end;
//end;
if FindFirst(Path + '*.*', faDirectory, SR) = 0 then
begin
try
repeat
if (SR.Name <> '.') and (SR.Name <> '..') then
TextFoundInFile(Path + SR.Name,'*.pas;*.dfm',tipo,tabela);
until FindNext(SR) <> 0;
finally
end;
end;
end;
Mi llamada a procedure
procedure TForm1.VarrerClick(Sender: TObject);
begin
ClientDataSet1.Open;
pth := IncludeTrailingPathDelimiter(edtDir.Directory);
while not ClientDataSet1.Eof do
begin
//TextFoundInFile(pth,'*.pas;*.dfm',ClientDataSet1.FieldByName('xtype').AsString,ClientDataSet1.FieldB yName('name').AsString);
BuscaTexto(pth,'*.pas;*.dfm',ClientDataSet1.FieldByName('xtype').AsString,ClientDataSet1.FieldByName ('name').AsString);
ClientDataSet1.Next;
end;
ListBox1.Items.SaveToFile(ExtractFilePath(Application.ExeName) + 'Fontes.csv');
end;