DateTime problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

in a huge project i have the following problem.
I create an object which contains many private members (i know that this is
not correct, but it is a single use migration program). The members will be
filled from database tables. In the fill method i see in debug mode the
correct values. At the source where i create the object the DateTime members
of the object are not present (error: cannot obtain value). An statement like
this
DateTime dat = object.startDate delivers 01/01/01.
If the object reference will be pass to a other method, inthis method is the
correct value present.
This all happens only for the DateTime members. Int32, Strinng are not
affected.

Who can help?

Josef Fieseler
 
Hi Josef,

I'm not sure I follow you

I assume you have a startDate member in your object, but I'm not sure what
happens to this member. Is it set to null, DateTime.Minimum or some other
value to begin with?

When does object.startDate return 01/01/01?

I suspect you are trying to use an uninitizalied DateTime object, although
I may have misunderstood your letter.
Remember also that the debugger may not always show the correct
information.
 
Hi Morten,

i will try to clarify my problem:

class X {public DateTime dat; ... public void LoadFromDB() }

Main:
X x = new x();
x.LoadFromDB; // If i debug the LoadFromDB method i see the correct date
value.
DateTime myDat = x.dat // Result = 01/01/01
AnyMethod(x)


public void AnyMethod(X x)
{
x.dat has the correct value!!!!!!!
}


Best regards
Joe
 
Hm are you saying that myDat ends up 01/01/01 even if x.dat is correct?
Or do you mean x.dat is wrong when you call x.dat the first time, but
correct when you call it from AnyMethod? I assume 01/01/01 is not the
correct value.

I can't tell from your pseudocode what is wrong. It would help if you
could show us some real code.

dat will be 01/01/01 since a class variable of type DateTime will be
initialized to DateTime.Minimum.
It will remain DateTime.Minimum until changed. If you read from the
database, but dat is unchanged I'd check how you store the database value
into dat.
 
Yes, x.dat is correct (debugging the Load-Method) and myDat not! If i debug
the
Statement "DateTime myDat = x.dat" the value of x.dat.Year is: "error:
cannot obtain value"
 
Hi Morton,

i have found the solution per luck:

After the statement
DateTime myDat = x.dat
follows many Method Calls with many params. Nearly all params are self
defined objects.
I have change all params from "by value" to "by reference" and behold it
works correctly!
Many thanks for this chat.
Joe
 
Back
Top