I'm trying to achieve something similar with the DateTime object in .Net but
for some reason it's just not behaving the way I would expect it to.
If've tried things like "myDate := convert.ToDateTime(nil);" which worked,
but then if I say "if &Object(myDate) = nil then..." the if translates to a
False where I'm expecting it to be True. I also haven't found any methods
which I can use to set and test for nil. Converting a zero to a DateTime
also raises exceptions.
My question is this: How do I set a date to nothing (either nil or 0) and
secondly, how do I test for the nothing value?
Many thanks
1) System.DateTime is a value type. There is no way you can set it to
nothing or nil.
2) You can store it in a variable as System.Object (thus boxed
version). In this case you can assign nil to the variable and test
with Assigned.
3) You can use your own nullable types (or download a .NET Nullables
library somewhere).
Basically a nullable value type is a type which contains a value
(DateTime in your case) and a Boolean property IsNull wich you can test.
Nullables will be available in the .NET 2.0 framework.
4) You could use 'magic values':
System.DateTime.MinValue (default value for a System.DateTime)
System.DateTime.MaxValue
It is a certainly a good idea to get some background on the .NET type
system, especially on Value types, Reference types and System.String
(immutable!).
Kind regards,
Dirk Andries
"Dirk Andries" <nos...@nospam.be> wrote in message
news:42d6...@newsgroups.borland.com...