Reputation: 35
I have populated a form with required components and pasted the example code into a buttonclick event.
I have added the TStringDynArrayarray and TSearchOption type declarations but I get compilation errors as shown below.
unit dirtest;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, System.Types, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, IOUtils, Vcl.StdCtrls;
type
TStringDynArray = Array of String;
TSearchOption = (soTopDirectoryOnly, soAllDirectories);
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
mmResults: TMemo;
cbIncludeDirectories: TCheckBox;
cbIncludeFiles: TCheckBox;
cbDoRecursive: TCheckBox;
edtPath: TEdit;
edtFileMask: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
LList: TStringDynArray;
I: Integer;
LSearchOption: TSearchOption;
begin
{ Select the search option }
if cbDoRecursive.Checked then
LSearchOption := TSearchOption.soAllDirectories
else
LSearchOption := TSearchOption.soTopDirectoryOnly;
try
{ For all entries use GetFileSystemEntries method }
if cbIncludeDirectories.Checked and cbIncludeFiles.Checked then
LList := TDirectory.GetFileSystemEntries(edtPath.Text, LSearchOption, nil;
{ For directories use GetDirectories method }
if cbIncludeDirectories.Checked and not cbIncludeFiles.Checked then
LList := TDirectory.GetDirectories(edtPath.Text, edtFileMask.Text,
LSearchOption);
{ For files use GetFiles method }
if not cbIncludeDirectories.Checked and cbIncludeFiles.Checked then
LList := TDirectory.GetFiles(edtPath.Text, edtFileMask.Text,
LSearchOption);
except
{ Catch the possible exceptions }
MessageDlg('Incorrect path or search mask', mtError, [mbOK], 0);
Exit;
end;
{ Populate the memo with the results }
mmResults.Clear;
for I := 0 to Length(LList) - 1 do
mmResults.Lines.Add(LList[I]);
end;
end.
The errors I get are thus...
[dcc32 Error] dirtest.pas(51): E2250 There is no overloaded version of 'GetFileSystemEntries' that can be called with these arguments [dcc32 Error] dirtest.pas(56): E2250 There is no overloaded version of 'GetDirectories' that can be called with these arguments [dcc32 Error] dirtest.pas(61): E2250 There is no overloaded version of 'GetFiles' that can be called with these arguments
Can you see what's going wrong? Thanks
Upvotes: 3
Views: 239
Reputation: 80287
Your type declaration introduces new types for TStringDynArray
and TSearchOption
while functions expect types declared in in-built units ( TStringDynArray = TArray<string>;
from System.Types
and TSearchOption
from IOUtils )
So just remove own type description
Upvotes: 6