2
votes

Using Delphi Seattle in W7 x64. When using a custom VCL style and you select a large amount of files (like 2-3k+), the filenames are corrupted. Without a custom style this doesn't happen.

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

On my end, this code results in only 769 files written to the log out of ~5000, and their initial path "z:" gets corrupted with other characters "?"

Any way to fix this?

Note: the new TFileOpenDialog does not seem to have this issue, however it does bring others as shown here: (besides being Vista+)

enter image description here
enter image description here

2
And if you would not use custom VCL style - it would be different ? - Arioch 'The
Works fine without the custom style. - hikari
My bet is then without custom styles the dialog goes into standard Windows Vista+ API call path, and like TFileOpenDialog manages to do it. But with non-standard VCL styles it has to override default Windows style and falls to limited pre-Vista modes. Try to install Windows 2000/XP and try the program there even without styles. Chances are it will only work with Vista+ anyway, so you would have no reason to avoid using TFileOpenDialog - Arioch 'The
Works fine without the custom style - Apparently not, according to the MS link that @Arioch'The posted in the answer below. - Ken White
It does in my testing, maybe it was fixed since that report? (almost 6 years old) - hikari

2 Answers

5
votes

You are experimenting this behavior because the size of the buffer passed to the Classic Open Dialog Box to retrieve the results of the selected file(s), the buffer is represented by the lpstrFile element which is part of the OPENFILENAME structure. The VCL internally set the size of this buffer to High(Word) - 16 (65519) bytes when the multi-select option is enabled and a MAX_PATH buffer size when the single file selection is enabled.

This is part of the VCL code (Vcl.Dialogs) which show this

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);
...
...

Starting with Windows Vista and the introduction of the New Dialogs (IFileOpenDialog), the selected files are returned by the IFileOpenDialog::GetResults method in a IShellItemArray, So the buffer limitation doesn't apply.

In summary this behavior is not caused by the VCL Styles.

Finally if you want use the modern dialogs with a custom style try the VCL Styles Utils project.

enter image description here

1
votes

That is not about Delphi it seems. Just five seconds in Google and we have this:

" File Open dialog cannot return more than 1000 files "

http://answers.microsoft.com/en-us/windows/forum/windows_7-files/shameful-limitation-file-open-dialog-cannot-return/bfff43fc-0da5-48d6-8703-dc0eac3c7581?auth=1