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...

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi retep,

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

Ciao, Mike
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...
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

yup, retep,

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

  TDate = Double;

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

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);
d :TDate;
d := 0;

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.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.