DateTime problem

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
 
M

Morten Wennevik

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

Guest

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
 
M

Morten Wennevik

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

Guest

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"
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top