Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Delphi 10编写SelectDirectory第三个重载_Delphi_Delphi 10 Seattle - Fatal编程技术网

用Delphi 10编写SelectDirectory第三个重载

用Delphi 10编写SelectDirectory第三个重载,delphi,delphi-10-seattle,Delphi,Delphi 10 Seattle,为什么这个不能编译?这似乎很简单,但我不明白。。。字符串数组是问题所在吗?错误是: [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

为什么这个不能编译?这似乎很简单,但我不明白。。。字符串数组是问题所在吗?错误是:

[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(const StartDirectory:string;out Directories:TArray;选项:TSelectDirFileDlgOpts=[];
const Title:string='';const foldernamelab:string='';const OkButtonLabel:string='':布尔值;重载;
}
程序TForm2.浏览1点击(发送方:TObject);
变量
iStartFolder:字符串;
iDirectories:字符串数组;
iSelectedFolder:字符串;
开始
iStartFolder:=桌面文件夹;
如果选择目录(iStartFolder、iDirectories、,
[sdHidePinnedPlaces、SDNodeReferenceLink、sdForceShowHidden、,
sdAllowMultiselect],“选择文件夹”,“文件夹”,“确定”),然后
ShowMessage(iDirectories[0]);
结束;

第三个
SelectDirectory()
重载的第二个参数是
out
参数,因此必须提供与参数类型相同的变量。您正试图传递字符串的
数组
变量,其中需要
System.TArray
变量,因此会出现错误。改用这个:

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;
程序TForm2.Browse1Click(发送方:TObject);
变量
iStartFolder:字符串;
i目录:焦油;
iSelectedFolder:字符串;
开始
iStartFolder:=桌面文件夹;
如果选择目录(iStartFolder、iDirectories、,
[sdHidePinnedPlaces、SDNodeReferenceLink、sdForceShowHidden、,
sdAllowMultiselect],“选择文件夹”,“文件夹”,“确定”),然后
ShowMessage(iDirectories[0]);
结束;

虽然
TArray
只是
字符串数组的别名,但当与
out
参数一起使用时,它们实际上是不同的类型。

好的。。。你是对的。谢谢,因为
TArray
string数组的类型不同。为什么要投反对票?如果没有人是消极的而不是积极的,几乎不可能在这里发布任何东西。@Bill:首先,你为什么要问Remy?他显然没有投反对票,否则他不会回答。其次,我没有投反对票,但可能是因为您发布了一个函数声明,要求您提供一个
TArray
和一个完全不同的代码(使用一个
字符串数组
);简单(仔细)阅读函数声明应该可以回答您的问题。Delphi是强类型的
TArray
array of string
是不同的-第一个是字符串的通用数组,第二个是字符串的动态数组。@KenWhite:
TArray
只是
array of string
的别名:
type TArray=array of T。但是,在这种情况下,当涉及
out
参数时,它们被视为不同的变量。您必须提供与参数类型相同的变量,您也可以在那里进行类型转换,但最好传递确切的类型。