[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Initialize TDate...

How can I initialize a TDate? I can't give it a nil value :-(

When I Create a variable of TDate it contains the value Now, and that messes up the rest of my program.

Of course I can give it some date which I know will not be used, but I'm hoping there is something predefined like nil...




0
retep
Asked:
retep
  • 3
  • 2
1 Solution
 
LischkeCommented:
Hi retep,

just set your variable to 0 (the base type is double).

Ciao, Mike
0
 
retepAuthor Commented:
Doesn't work. To give it the value 0 is the same as giving it the value Now. And that is excatly what im trying to prevent.

I want it to contain something different then a date.

Like normally when u use objects u can give then the value Nil, and they stop pointing at data...
0
 
LischkeCommented:
Hu?? "Now" is a totally different value than 0. I don't understand why you can't use 0. You cannot expect a variable to hold a different value than it is declared for. TDate holds dates and period. Assigning nil to an object is still a pointer with the special meaning that it shouldn't be used to dereference (Actually there IS a memory location at address 0 but this is specially guarded to help an application to find nil pointers. But this is a totally different theme.).

Giving a date the value 0 has the same meaning. It just says: DON'T USE THIS VALUE. What's wrong with this approach?

Ciao, Mike
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
kretzschmarCommented:
yup, retep,

mike is right, because tdate isn't an object it is exact

type
  TDate = Double;

and represents a double
therefore you can only give a value in the range of a double, no other thing.

meikl
0
 
retepAuthor Commented:
Okay guess you are right, because you can ask if d = 0 (D:TDate), and that is what I need.

Here is what confused me:

procedure TForm1.Button1Click(Sender: TObject);
Var
d :TDate;
begin
d := 0;
Showmessage(DateToStr(D));
end;

This procedure shows the string '30-11-99', and therefore I thought that the value wasn't 0.

I still think it is strange eventhough I see that you are right. Do you have an explanation to why a date is shown?  

Thanks for the answer.
Regards
Peter


0
 
LischkeCommented:
Actually, TDateTime is the relative distance to 12/30/1899 12:00 am. ShowMessage shows you only the last two digits of the year so you thought it would show a "valid" data. See the description of TDateTime for more information.

Ciao, Mike
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now