我已经用所需的组件填充了一个表单,并将示例代码粘贴到了 buttonclick 事件中。
我添加了 TStringDynArrayarray 和 TSearchOption 类型声明,但出现编译错误,如下所示。
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.
我得到的错误是......
[dcc32 错误]dirtest.pas(51):E2250 没有可以使用这些参数调用的“GetFileSystemEntries”的重载版本 [dcc32 Error]dirtest.pas(56):E2250 没有“GetDirectories”的重载版本可以使用这些参数调用 [dcc32 Error]dirtest.pas(61): E2250 没有可以使用这些参数调用的“GetFiles”的重载版本
你能看出出了什么问题吗?谢谢