Delphi 11.3 - SHGetFileInfo引发ERangeError

tzdcorbm  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(164)

我有一些代码调用SHGetFileInfo来检索系统图标列表:

FileIcons: TImageList;

procedure LoadFileIcons;
var
  listHandle: Integer;
  shFileInfo: TSHFileInfo;
begin
  listHandle:= SHGetFileInfo('', 0, shFileInfo, Sizeof(shFileInfo),
                             SHGFI_SYSICONINDEX or SHGFI_LARGEICON);

  if (listHandle <> 0) then
  begin
    FileIcons.Handle:=listHandle;
    FileIcons.ShareImages:=true;
  end;
end

在 Delphi 上,这工作正常,我能够加载图标和显示文件与适当的图标。在 Delphi 11.3中,它引发了以下异常:

Project Project.exe raised exception class ERangeError with message 'Range check error at address 00000000035C7A99'.

Delphi 10.4和Delphi 11.3之间有什么变化吗?我该怎么解决?

xv8emn3q

xv8emn3q1#

已解决将listHandle声明为DWORD_PTR的问题:

FileIcons: TImageList;

procedure LoadFileIcons;
var
  listHandle: DWORD_PTR;
  shFileInfo: TSHFileInfo;
begin
  listHandle:= SHGetFileInfo('', 0, shFileInfo, Sizeof(shFileInfo),
                             SHGFI_SYSICONINDEX or SHGFI_LARGEICON);

  if (listHandle <> 0) then
  begin
    FileIcons.Handle:=listHandle;
    FileIcons.ShareImages:=true;
  end;
end

相关问题