TDateTime in Delphi.Net

In Delphi for Win32 the TDateTime type is a Double, but in Delphi.Net it is declared as a record which uses a System.DateTime to hold the date / time value. For the most part this was done in such a way as to be transparent. However, there is one aspect of the new implementation that is not portable between Win32 and .Net.

In both Win32 and .Net a TDateTime that is a member of a class is initialized to a value of zero when the class is created. In Win32 the standard way to test for this was if (FDate = 0). This doesn’t work in .Net programs. You need to cast the date as a Double first. So the equivalent .Net code is if (Double(FDate) = 0). This is at least portable from .Net to Win32 but existing Win32 programs will fail.

Leave a Reply