Delphi TDateTime variable will not initialize in Delphi 2010

665 Views Asked by At

I have created a simple form in Delphi 2010 with a single button in the code for the button I put:

procedure TForm1.Button1Click(Sender: TObject);
var
     myDateTime:TDateTime;
begin
     myDateTime:=now; // shows as 12/30/99 in debugger
end;

When I run this exact same code in Delphi XE2, I get the current date/time in the value for myDateTime.

I'm thinking I must have something set incorrectly in the Delphi 2010 project environment, but cannot think of what it might be.

Any help would be much appreciated.

Thanks!

Discovered issue, compiler settings were for Code Generation Optimization set to true, and the value apparently gets represented as the default for TDateTime. When I changed the optimization setting to false, I can see the value.

1

There are 1 best solutions below

0
On

I think the reason you are not seeing myDateTime is that it never gets used.
As such it is a candidate for dead code removal.
Obviously removed code cannot be executed and you can not see the value.

If you disable the optimization your (useless) code does not get removed and you can see the var being filled.