0

I have a listbox with one item 'ABC'.

The following code works fine under Win32:

h := DrawText(ListBox1.Canvas.Handle, PChar(ListBox1.Items[0]), -1, R, DT_CALCRECT);

After that line h = 19, which is correct. Using the same code under Win64 returns 0, e.g. h = 0

SysErrorMessage(GetLastError) returns "The operation completed successfully"

Now if I modify the code this way, it works both on Win32 and Win64.

s := ListBox1.Items[0];
h := DrawText(ListBox1.Canvas.Handle, PChar(s), -1, R, DT_CALCRECT);

After this change h = 19 on Win32 and Win64. Any ideas why a temporary variable is needed under Win64?

dwrbudr
  • 607
  • 4
  • 8
  • Which Delphi version and what is the size of `R`? – Tom Brunberg Oct 25 '22 at 08:18
  • What you seem to be attempting can be solved with h := ListBox1.ItemHeight if I'm not mistaken. – HeartWare Oct 25 '22 at 08:24
  • I'm using Delphi 11.2, R is defined as TRect – dwrbudr Oct 25 '22 at 10:19
  • May be caused by a different order of parameter evaluation in Win32 and Win64. I had a similar problem described and answered here: https://stackoverflow.com/questions/34358110/why-does-a-call-to-getdibits-fail-on-win64 – Uwe Raabe Oct 25 '22 at 10:35
  • Parameter order doesn't matter here. With the original one liner code the compiler does need to assign the string to a temporary local. If the code is failing then I guess that isn't happening. It's very likely a bug in specific versions of the compiler because as an XE7 user I am reasonably confident that this works as expected. I'd submit a bug report. – David Heffernan Oct 25 '22 at 11:30
  • I also think that it has nothing to do with parameter evaluation. The call to that function is made in a button OnClick event and at that time the ListBox is fully visible and its Handle is allocated. Indeed the ListBox.Items.Get (TListBoxStrings) uses SendMessage to return the string. – dwrbudr Oct 25 '22 at 11:42

0 Answers0