使用 Delphi 10 编译选择目录第三次重载
Compling SelectDirectory Third Overload with Delphi 10
为什么不能编译?看起来很简单,但我不明白......是字符串数组的问题吗?错误是:
[dcc32 Error] Unit1.pas(94): E2250 There is no overloaded version of 'SelectDirectory' that can be called with these arguments.
代码如下:
{
function SelectDirectory(const StartDirectory: string; out Directories: TArray<string>; Options: TSelectDirFileDlgOpts = [];
const Title: string = ''; const FolderNameLabel: string = ''; const OkButtonLabel: string = ''): Boolean; overload;
}
procedure TForm2.Browse1Click(Sender: TObject);
var
iStartFolder: string;
iDirectories: Array of string;
iSelectedFolder: string;
begin
iStartFolder := DesktopFolder;
if SelectDirectory(iStartFolder, iDirectories,
[sdHidePinnedPlaces, sdNoDereferenceLinks, sdForceShowHidden,
sdAllowMultiselect], 'Select Folder', 'Folder', 'Ok') then
ShowMessage(iDirectories[0]);
end;
第三个 SelectDirectory()
重载的第二个参数是一个 out
参数,因此您必须提供与该参数类型相同的变量。您正在尝试传递一个 array of string
变量,而应该是 System.TArray<String>
变量,因此出现错误。改用这个:
procedure TForm2.Browse1Click(Sender: TObject);
var
iStartFolder: string;
iDirectories: TArray<string>;
iSelectedFolder: string;
begin
iStartFolder := DesktopFolder;
if SelectDirectory(iStartFolder, iDirectories,
[sdHidePinnedPlaces, sdNoDereferenceLinks, sdForceShowHidden,
sdAllowMultiselect], 'Select Folder', 'Folder', 'Ok') then
ShowMessage(iDirectories[0]);
end;
虽然 TArray<String>
只是 array of string
的别名,但当与 out
参数一起使用时,它们实际上是不同的类型。
为什么不能编译?看起来很简单,但我不明白......是字符串数组的问题吗?错误是:
[dcc32 Error] Unit1.pas(94): E2250 There is no overloaded version of 'SelectDirectory' that can be called with these arguments.
代码如下:
{
function SelectDirectory(const StartDirectory: string; out Directories: TArray<string>; Options: TSelectDirFileDlgOpts = [];
const Title: string = ''; const FolderNameLabel: string = ''; const OkButtonLabel: string = ''): Boolean; overload;
}
procedure TForm2.Browse1Click(Sender: TObject);
var
iStartFolder: string;
iDirectories: Array of string;
iSelectedFolder: string;
begin
iStartFolder := DesktopFolder;
if SelectDirectory(iStartFolder, iDirectories,
[sdHidePinnedPlaces, sdNoDereferenceLinks, sdForceShowHidden,
sdAllowMultiselect], 'Select Folder', 'Folder', 'Ok') then
ShowMessage(iDirectories[0]);
end;
第三个 SelectDirectory()
重载的第二个参数是一个 out
参数,因此您必须提供与该参数类型相同的变量。您正在尝试传递一个 array of string
变量,而应该是 System.TArray<String>
变量,因此出现错误。改用这个:
procedure TForm2.Browse1Click(Sender: TObject);
var
iStartFolder: string;
iDirectories: TArray<string>;
iSelectedFolder: string;
begin
iStartFolder := DesktopFolder;
if SelectDirectory(iStartFolder, iDirectories,
[sdHidePinnedPlaces, sdNoDereferenceLinks, sdForceShowHidden,
sdAllowMultiselect], 'Select Folder', 'Folder', 'Ok') then
ShowMessage(iDirectories[0]);
end;
虽然 TArray<String>
只是 array of string
的别名,但当与 out
参数一起使用时,它们实际上是不同的类型。