gpt4 book ai didi

Delphi:TOpenDialog + VCL 样式会损坏大量文件的文件名

转载 作者:行者123 更新时间:2023-12-02 13:30:34 30 4
gpt4 key购买 nike

在 W7 x64 中使用 Delphi Seattle。当使用自定义 VCL 样式并且选择大量文件(例如 2-3k+)时,文件名会损坏。如果没有自定义样式,这种情况就不会发生。

program Project1;

uses
Vcl.Forms,
Unit1 in 'Unit1.pas' {Form1},
Vcl.Themes,
Vcl.Styles;

{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
TStyleManager.TrySetStyle('Onyx Blue');
Application.CreateForm(TForm1, Form1);
Application.Run;
end.


procedure TForm1.FormCreate(Sender: TObject);
Var s: string;
ts: TStringList;
begin
if OpenDialog1.Execute then begin
ts := TStringList.Create;
for s in OpenDialog1.Files do
ts.Add(s);
end else Exit;
ts.SaveToFile('z:\files.txt');
ts.Free;
end;

object OpenDialog1: TOpenDialog
Filter = 'Pictures (jpg,png,bmp,gif)|*.jpg;*.png;*.bmp;*.gif|All Files|*.*'
Options = [ofReadOnly, ofAllowMultiSelect, ofEnableSizing, ofForceShowHidden]
Title = 'Select files to upload'
Left = 201
Top = 64
end

就我而言,此代码仅导致约 5000 个文件写入日志中的 769 个文件,并且它们的初始路径“z:”被其他字符“?”损坏

有办法解决这个问题吗?

注意:新的 TFileOpenDialog 似乎没有这个问题,但它确实带来了其他问题,如下所示:(除了 Vista+)

enter image description here
enter image description here

最佳答案

您正在试验此行为,因为传递给 Classic Open Dialog Box 的缓冲区大小要检索所选文件的结果,缓冲区由 lpstrFile 元素表示,该元素是 OPENFILENAME 的一部分结构。当启用多选选项时,VCL 在内部将此缓冲区的大小设置为 High(Word) - 16 (65519) 字节;当启用单选选项时,VCL 会在内部将此缓冲区大小设置为 MAX_PATH 缓冲区大小。文件选择已启用。

这是显示此内容的 VCL 代码 (Vcl.Dialogs) 的一部分

function TOpenDialog.DoExecute(Func: Pointer; ParentWnd: HWND): Bool;
const
MultiSelectBufferSize = High(Word) - 16;
...
...
if ofAllowMultiSelect in FOptions then
nMaxFile := MultiSelectBufferSize else
nMaxFile := MAX_PATH;
SetLength(TempFilename, nMaxFile + 2);
lpstrFile := PChar(TempFilename);
...
...

从 Windows Vista 开始并引入新对话框 (IFileOpenDialog) ,所选文件由 IFileOpenDialog::GetResults 返回方法 IShellItemArray ,因此缓冲区限制不适用。

总之,此行为不是由 VCL 样式引起的

最后,如果您想使用具有自定义样式的现代对话框,请尝试 VCL Styles Utils项目。

enter image description here

关于Delphi:TOpenDialog + VCL 样式会损坏大量文件的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36769595/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com