使用Delphi 10编译SelectDirectory第三次重载

时间:2015-08-31 23:54:39

标签: 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: 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;

1 个答案:

答案 0 :(得分:7)

第三个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参数一起使用时,它们实际上是不同的类型。