I try to revise some LEGACY CODE that I wrote back in the Delphi 10.1 Berlin. Unfortunately, it does not compile in the current Delphi 11 Alexandria, as it shows this compiler error message:
[dcc32 Error] AppDocUtils.pas(1164): Cannot capture symbol 'FileSearch'
procedure PACountFilesInAppDocsTask(const ADir: string; const BAllApps: Boolean);
var
ThisTask: ITask;
begin
ThisTask := TTask.Create(
procedure()
var
count: Integer;
procedure FileSearch(const ThisDir: string);
var
SR: System.SysUtils.TSearchRec;
begin
if System.SysUtils.FindFirst(IncludeTrailingPathDelimiter(ThisDir) + '*', faAnyFile, SR) = 0 then
begin
try
repeat
if (SR.Attr and faDirectory) = 0 then
begin
Inc(Count);
end
else if (SR.Name <> '.') and (SR.Name <> '..') then
begin
FileSearch(IncludeTrailingPathDelimiter(ThisDir) + SR.Name);
end;
until FindNext(SR) <> 0;
finally
System.SysUtils.FindClose(SR);
end;
end;
end;
begin
count := 0;
FileSearch(ADir);
TThread.Synchronize(nil,
procedure
begin
if BAllApps then
FilesCountInAllApps := count
else
FilesCountInThisApp := Count;
end);
end);
ThisTask.Start;
end; // error HERE!