0

I use Delphi 10.4 and build 32 and 64 Bit applications. I noticed that the initialization of boolean variables depends on the type of application (32 bit and 64 bit).

I build a simple app. Here is my code:

procedure TForm1.Button1Click(Sender: TObject);
var
  value: boolean;
begin
  ShowMessage(value.ToString);
end;

In 32 bit value is true and in 64 bit value is false.

Is this a normal behaviour? And how can I change it?

dmeier
  • 31
  • 3
  • 5
    In Delphi, local variables of non-managed types are never initialized. Hence, the initial value is completely undefined ("random": whatever your computer happens to have at that part in its memory). This has always been the case, so in 32-bit, the value is undefined, and in 64-bit, it is also undefined. If you have been assuming that local boolean variables are always initialized to something, you have had a bugs in your code, and your code will seemingly "randomly" malfunction! – Andreas Rejbrand Aug 28 '20 at 08:41
  • If you want a variable to have a certain value you must assign that value to it. In delphi this is done with the assignment operator `:=`. If you would like `value` to be true you write `value := true;`. – J... Aug 28 '20 at 11:18

0 Answers0