Hola Paulao.
La acción que realiza el algorítmo, leer cada línea de cada archivo .pas y .dfm hasta encontrar la palabra buscada, como toda búsqueda secuencial, es intrínsecamente lenta y por supuesto su tiempo de ejecución está relacionada en forma directa a la cantidad de archivos a revisar.
Creo también, que haber modificado la función por procedimiento e incluir la carga del
TListBox dentro de la misma hace que todo sea un poco más lento. Así que retomando la función
original, yo probaría si mejora el rendimiento de este modo:
Código Delphi
[-]
function TForm1.TextFoundInFile(Ruta: string; const FileMask, Buscado, tipo: string): TStrings;
var
SR: TSearchRec;
txt: TextFile;
Row: string;
Found: Boolean;
NroExt: TStrings;
i: Integer;
begin
NroExt:= TStringList.Create;
try
NroExt.Delimiter:= ';';
NroExt.DelimitedText:= FileMask;
Ruta:= IncludeTrailingPathDelimiter(Ruta);
Result:= TStringList.Create;
for i:= 0 to NroExt.Count - 1 do
begin
if FindFirst(Ruta + NroExt[i], faAnyFile - faDirectory, SR) = 0 then
repeat
Application.ProcessMessages;
AssignFile(txt, Ruta + SR.Name);
Reset(txt);
Found:= False;
while not Eof(txt) and not Found do
begin
Readln(txt, Row);
if Pos(Buscado, Row) > 0 then
begin
Result.Add(tipo + ';' + Buscado + ';' + SR.Name);
Found:= True
end
end;
CloseFile(txt);
until FindNext(SR) <> 0
end
finally
NroExt.Free
end
end;
LLamada:
Código Delphi
[-]
...
ListBox1.Items:= TextFoundInFile( pth,'*.pas;*.dfm',
ClientDataSet1.FieldByName('xtype').AsString,
ClientDataSet1.FieldByName('name').AsString);
...
Pero como te mencioné arriba, las búsquedas secuenciales son de por sí lentas y si sumamos a eso la lectura secuencial del DataSet...
Un saludo.