Recent

Author Topic: QWord properties and "default"  (Read 731 times)

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
QWord properties and "default"
« on: February 13, 2023, 08:34:22 pm »
Hi,

Does anyone with a modern delphi know if Delphi allows a property of QWord to have a default value which is larger than High(DWord)?
Code: Pascal  [Select][+][-]
  1. type
  2.   TA = class
  3.   private
  4.     FNumber: QWord;
  5.   public
  6.     property Number: QWord read FNumber write FNumber default QWord(High(DWord))+1;
  7.   end;

Fpc complains:
Code: [Select]
Error: range check error while evaluating constants (4294967296 must be between -2147483648 and 4294967295)
Also: the range reported by fpc is a bit strange for a QWord..., but that's not really the issue riht now.

Bart
« Last Edit: February 13, 2023, 08:38:15 pm by Bart »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2048
  • Fifty shades of code.
    • Delphi & FreePascal
Re: QWord properties and "default"
« Reply #1 on: February 13, 2023, 08:57:26 pm »
UInt64 is the biggest supported number in Delphi, if that is not enough we need to use unit "BigNumber".
QWORD Delphi does not have at all.
Casting on default values never worked AFAIK.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2048
  • Fifty shades of code.
    • Delphi & FreePascal
Re: QWord properties and "default"
« Reply #2 on: February 13, 2023, 09:01:25 pm »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Thaddy

  • Hero Member
  • *****
  • Posts: 14357
  • Sensorship about opinions does not belong here.
Re: QWord properties and "default"
« Reply #3 on: February 13, 2023, 09:01:39 pm »
Just tested against 10.3. Fails. As does FPC. It is probably the property vs the field.
Anyway, how did you stumble on such a border case? If it is..
Compilable example?
« Last Edit: February 13, 2023, 09:04:26 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: QWord properties and "default"
« Reply #4 on: February 13, 2023, 09:10:25 pm »
Quote
Also: the range reported by fpc is a bit strange for a QWord..., but that's not really the issue riht now.

IMO the error message is not for QWord but generally for integers since for Int64 it's not possible too.
Code: Pascal  [Select][+][-]
  1. property Number: int64 read FNumber write FNumber default Int64($7FFFFFFFFFFFFFFF);
The same error.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: QWord properties and "default"
« Reply #5 on: February 13, 2023, 10:05:26 pm »
UInt64 is the biggest supported number in Delphi, if that is not enough we need to use unit "BigNumber".
QWORD Delphi does not have at all.

QWORD = UINT64.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: QWord properties and "default"
« Reply #6 on: February 13, 2023, 10:13:04 pm »
Anyway, how did you stumble on such a border case? If it is..

I tried to have a HKey property set to default to HKEY_CURRENT_USER.
Tha won't compile on 64-bit, because (as by design, as it turns out), while HKey on win64 is QWord (well, THande = QWord and HKey = THandle), HKEY_CURRENT_USER is defined as HKEY(longint($80000001)), which gets sign extended in the cast to QWord (as the longint is negative) and so on Win64, it will be $FFFFFFFF80000001 as opposed to 32-bit where it will be $80000001 (DWORD).

So, this would not compile on 64-bit, but it did on 32-bit:
Code: Pascal  [Select][+][-]
  1.   property RooKey: HKey read FRootKey write FRootKey default HKEY_CURRENT_USER;

Bart

 

TinyPortal © 2005-2018