Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undeclared identifier soAllDirectories

I'm trying to use the TDirectory.GetFiles function, but when I add a TSearchOptions third parameter to force a recursive search the compiler raises an error saying that soAllDirectories has not been declared.

uses System.IOutils,
     System.Types;

procedure TfrmConversio.btnConversioClick(Sender: TObject);
var FilesPas: TStringDynArray;
begin
  FilesPas := TDirectory.GetFiles('C:\Project', '*.pas', soAllDirectories);
  ProgressBar1.Max := Length(FilesPas);
end;

What am I doing wrong ?. I can see that constant in System.IOUtils.

Thank you.

like image 719
Marc Guillot Avatar asked Aug 19 '20 18:08

Marc Guillot


1 Answers

You need to write

TDirectory.GetFiles('C:\Project', '*.pas', TSearchOption.soAllDirectories);

The reason is that the compiler directive {$SCOPEDENUMS ON} is found before the definition of the TSearchOption type. This means precisely that you need to qualify the enumeration's constants with the type name.

From the documentation:

The $SCOPEDENUMS directive enables or disables the use of scoped enumerations in Delphi code. More specifically, $SCOPEDENUMS affects only definitions of new enumerations, and only controls the addition of the enumeration's value symbols to the global scope.

In the {$SCOPEDENUMS ON} state, enumerations are scoped, and enum values are not added to the global scope. To specify a member of a scoped enum, you must include the type of the enum.

like image 153
Andreas Rejbrand Avatar answered Jan 22 '23 21:01

Andreas Rejbrand