1

when looking in System.pas there TDate und TDateTime defined as the following:

  TDateTime = type Double;

  TDate = type TDateTime;
  TTime = type TDateTime;

obviously TDate and TDateTime are the same.

I just struggled working with TDate and TDateTime bacause I expected that TDate only contains the date-part and not also the time-part.

Now I'm wondering: What the sense behind this? When I declare a variable as TDate, then It should contain a date, and not a dat and a time-value.

user1619275
  • 355
  • 1
  • 6
  • 14

1 Answers1

8

They are not the same. If the declarations had been

TDate = TDateTime;
TTime = TDateTime;

they had been the same. With the additional type, although they are still technically the same, i.e., they are still doubles, they can be told apart. This, for instance, makes it possible to use different property editors in the Object Inspector for the two types (a date picker and a time picker, respectively), while you may use a 'date-time' picker for TDateTime.

In addition, even if it weren't for this, it might be good to use different 'aliases' for different purposes. This might make your source code easier to understand. For instance, if you do

var
  StartTime: TDate;

then you know that StartTime contains only information about the date, and not the time (unless you abuse the norms).

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • 2
    In addition, you cannot use a TDateTime as an actual var parameter, when a TDate is declared. – Uwe Raabe Aug 29 '12 at 10:40
  • Of course it'S good that TDate and TTime types exists, but when a TDate would contain a Date (and not date AND time) and a TTime would contain only a time-value - then code would be even more easy to understand, I think ;). And when the programmer tries to "abuse the norms" the compiler should give an error or at least a warning. – user1619275 Aug 30 '12 at 07:17
  • That was not the question. Poster is wondering why a TDate type holds time information at all. Obviously, he does not want to have to crop off time information with a date=int(TDate) every single time he needs just a date, which I think is a very reasonable positon. – Tuncay Göncüoğlu Oct 31 '14 at 09:17
  • In that regard, the definition should have been: TDate = type integer; – Tuncay Göncüoğlu Oct 31 '14 at 09:18