Delphi Rio 帮助中包含的最脏的示例代码。有什么明显的我遗漏了吗?
dirtest example code included in Delphi Rio help. Is there something obvious I have omitted?
我已经用所需的组件填充了一个表单,并将示例代码粘贴到按钮点击事件中。
我已经添加了 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 Error] dirtest.pas(51): E2250 没有可以用这些参数调用的 'GetFileSystemEntries' 的重载版本
[dcc32 错误] dirtest.pas(56): E2250 没有可以使用这些参数调用的 'GetDirectories' 的重载版本
[dcc32 错误] dirtest.pas(61): E2250 没有可以使用这些参数调用的 'GetFiles' 的重载版本
你能看出哪里出了问题吗?
谢谢
您的类型声明为 TStringDynArray
和 TSearchOption
引入了 new 类型,而函数期望在内置单元中声明的类型( TStringDynArray = TArray<string>;
来自System.Types
和 TSearchOption
来自 IOUtils )
所以只需删除自己的类型描述
我已经用所需的组件填充了一个表单,并将示例代码粘贴到按钮点击事件中。
我已经添加了 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 Error] dirtest.pas(51): E2250 没有可以用这些参数调用的 'GetFileSystemEntries' 的重载版本 [dcc32 错误] dirtest.pas(56): E2250 没有可以使用这些参数调用的 'GetDirectories' 的重载版本 [dcc32 错误] dirtest.pas(61): E2250 没有可以使用这些参数调用的 'GetFiles' 的重载版本
你能看出哪里出了问题吗? 谢谢
您的类型声明为 TStringDynArray
和 TSearchOption
引入了 new 类型,而函数期望在内置单元中声明的类型( TStringDynArray = TArray<string>;
来自System.Types
和 TSearchOption
来自 IOUtils )
所以只需删除自己的类型描述