-3

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.
AmigoJack
  • 5,234
  • 1
  • 15
  • 31
malom
  • 223
  • 2
  • 11
  • This question does not meet the quality guidelines for SO. Please provide a [mre] that demonstrates the issue. Questions that you intend to self-answer must still meet the question standards here. – Ken White Oct 25 '22 at 03:09
  • I'm very happy being downvoted twice after a long day spent with this problem. In my personal opinion, the question was readable and the answer is sufficient to help others not to go through the same, or at least to show the direction. Of coarse, both could be improved, especially the answer, because I don't know if I should modify the original VCL sources or copy the unit to a different location and add to the project that uses it. It would worth to talk about it, instead of downvoting. – malom Oct 25 '22 at 08:02
  • I too find the downvotes here a bit surprising and aggressive. – Andreas Rejbrand Oct 25 '22 at 08:36
  • 1
    Your original question lacked both formattings and actual code - I would have downvoted that, too. Proper tags and the version of that component/Delphi are still missing. – AmigoJack Oct 25 '22 at 09:09
  • @AmigoJack: It turned out, that the Delphi version is relevant. Originally I thought that all Delphi versions that support Win64 platform have this bug, because the FImages: Integer field declaration didn't change from XE2 to 11.1. I would revoke my answer as a solution, since I have not enough knowledge to verify it. – malom Oct 25 '22 at 11:45
  • Unbound to how many versions you know/can test it always helps to name the actual details that were used (version, OS platform, EXE platform, file line numbers...) as this can always change in the future when your Q and A become older. Likewise proper tags to the Q attract more people/make it easier to find such a Q (and A). – AmigoJack Oct 25 '22 at 13:08
  • @AndreasRejbrand: Look at the edit history for this question, version 1. Would you have downvoted it? If not, I'd be very disappointed in you. This post was intended to be a self-answered questions, and both the question and answer are required to meet the usual SO quality standards. – Ken White Oct 25 '22 at 18:57
  • @KenWhite: I hadn't seen that version, and of course I agree it isn't a good question. – Andreas Rejbrand Oct 25 '22 at 18:59

1 Answers1

0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
malom
  • 223
  • 2
  • 11
  • This is a known bug that had already been reported to Embarcadero before this question was asked: [RSP-38488: TShellTreeView crashes on 64bit when UseShellImages:=True](https://quality.embarcadero.com/browse/RSP-38488) It also affects `TShellComboBox` and `TShellListView`, too – Remy Lebeau Feb 06 '23 at 22:04