DateTime problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JFieseler

    DateTime problem

    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.startDat e 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
  • JFieseler

    #2
    RE: DateTime problem

    Correction: I mind certainly "public members"

    "JFieseler" wrote:
    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.startDat e 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

    Comment

    • Morten Wennevik

      #3
      Re: DateTime problem

      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.Minimu m or some other
      value to begin with?

      When does object.startDat e 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.



      On Fri, 11 Aug 2006 11:48:01 +0200, JFieseler
      <JFieseler@disc ussions.microso ft.comwrote:
      Correction: I mind certainly "public members"
      >
      "JFieseler" wrote:
      >
      >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.startDat e 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


      --
      Happy Coding!
      Morten Wennevik [C# MVP]

      Comment

      • JFieseler

        #4
        Re: DateTime problem

        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


        "Morten Wennevik" wrote:
        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.Minimu m or some other
        value to begin with?
        >
        When does object.startDat e 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.
        >
        >
        >
        On Fri, 11 Aug 2006 11:48:01 +0200, JFieseler
        <JFieseler@disc ussions.microso ft.comwrote:
        >
        Correction: I mind certainly "public members"

        "JFieseler" wrote:
        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.startDat e 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
        >
        >
        >
        --
        Happy Coding!
        Morten Wennevik [C# MVP]
        >

        Comment

        • Morten Wennevik

          #5
          Re: DateTime problem

          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.Minimu m.
          It will remain DateTime.Minimu m until changed. If you read from the
          database, but dat is unchanged I'd check how you store the database value
          into dat.


          On Fri, 11 Aug 2006 12:42:02 +0200, JFieseler
          <JFieseler@disc ussions.microso ft.comwrote:
          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
          >
          >
          "Morten Wennevik" wrote:
          >
          >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.Minimu m or some
          >other
          >value to begin with?
          >>
          >When does object.startDat e 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.
          >>
          >>
          >>
          >On Fri, 11 Aug 2006 11:48:01 +0200, JFieseler
          ><JFieseler@dis cussions.micros oft.comwrote:
          >>
          Correction: I mind certainly "public members"
          >
          "JFieseler" wrote:
          >
          >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.startDat e 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
          >>
          >>
          >>
          >--
          >Happy Coding!
          >Morten Wennevik [C# MVP]
          >>


          --
          Happy Coding!
          Morten Wennevik [C# MVP]

          Comment

          • JFieseler

            #6
            RE: DateTime problem

            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"

            "JFieseler" wrote:
            Correction: I mind certainly "public members"
            >
            "JFieseler" wrote:
            >
            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.startDat e 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

            Comment

            • JFieseler

              #7
              Re: DateTime problem

              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

              "Morten Wennevik" wrote:
              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.Minimu m.
              It will remain DateTime.Minimu m until changed. If you read from the
              database, but dat is unchanged I'd check how you store the database value
              into dat.
              >
              >
              On Fri, 11 Aug 2006 12:42:02 +0200, JFieseler
              <JFieseler@disc ussions.microso ft.comwrote:
              >
              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


              "Morten Wennevik" wrote:
              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.Minimu m or some
              other
              value to begin with?
              >
              When does object.startDat e 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.
              >
              >
              >
              On Fri, 11 Aug 2006 11:48:01 +0200, JFieseler
              <JFieseler@disc ussions.microso ft.comwrote:
              >
              Correction: I mind certainly "public members"

              "JFieseler" wrote:

              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.startDat e 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
              >
              >
              >
              --
              Happy Coding!
              Morten Wennevik [C# MVP]
              >
              >
              >
              >
              --
              Happy Coding!
              Morten Wennevik [C# MVP]
              >

              Comment

              Working...