Delphi 11 TShellTreeView causes access violation on Win64 platform at application startup

334 Views Asked by At

TShellTreeView component in Vcl.Shell.ShellCtrls unit causes an access violation in TWinControl.DefaultHandler() on Win64 platform at application startup when the form initializes.

To reproduce the bug:

  1. Create a new VCL Forms application and put a TShellTreeView component onto the form. Or, alternatively paste this minimal project source into a file named 'ShellTreeViewTest.dpr' and open the project with the Delphi IDE:

    program ShellTreeViewTest;
    uses 
      Vcl.Forms, Vcl.Controls, Vcl.Shell.ShellCtrls; 
    var 
      Form: TForm;
    begin
      Application.Initialize;
      Application.CreateForm(TForm, Form);
      with TShellTreeView.Create(Form) do
        Parent := Form;
      Application.Run;
    end.
    
  2. Then add platform "Windows 64 bit" to the project.

  3. Compile and run.

I use Delphi 11.1 Alexandria.

  • The access violation raises only if "Support high-entropy 64-bit address space layout randomization (ASLR)" is enabled in the Project options/Linking tab. It is enabled by default, so the bug is reproducible in Delphi 11.
  • But in Delphi XE2 there is no such checkbox in the project options.
1

There are 1 best solutions below

1
malom On

The AV is caused by the TCustomShellTreeView.FImages field being declared as an Integer; it is initialized by a call to SHGetFileInfo(), which returns a DWORD_PTR. Replacing FImages: Integer with FImages: DWORD_PTR solves the problem.

The TCustomShellComboBox.FImages, TCustomShellListView.FLargeImages, and TCustomShellListView.FSmallImages fields also need to be changed accordingly.