Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DateTimePicker error debugging

DateTimePicker error debugging

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebuggingquestionannouncement
11 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jose Luis Sogorb

    Hi: I have this code: Into DoDataExchange DDX_Control(pDX, IDC_DATETIMEPICKER, m_date); Into own function: void CDialogSd::OnOK() { CDialog::OnOK(); CTime time; m_date.GetTime(time); day.Format("%d",time.GetDay()); month.Format("%d",time.GetMonth()); year.Format("%d",time.GetYear()); } It works fine when compiling in Release Mode, but find an exception when running in Debug Mode and it breaks at: _AFX_INLINE int CTime::GetDay() const { return GetLocalTm(NULL)->tm_mday; } Looking for the 'time' value it appears as 1108057231 (%ld value)in Release and -365867584 when debugging. What could be the problem? Thanks

    S Offline
    S Offline
    Steve Mayfield
    wrote on last edited by
    #2

    Try moving CDialog::OnOK() to the end of your OnOK routine...

    void CDialogSd::OnOK()
    {
    CTime time;
    m_date.GetTime(time);
    day.Format("%d",time.GetDay());
    month.Format("%d",time.GetMonth());
    year.Format("%d",time.GetYear());
    CDialog::OnOK();
    }

    Steve

    J 1 Reply Last reply
    0
    • S Steve Mayfield

      Try moving CDialog::OnOK() to the end of your OnOK routine...

      void CDialogSd::OnOK()
      {
      CTime time;
      m_date.GetTime(time);
      day.Format("%d",time.GetDay());
      month.Format("%d",time.GetMonth());
      year.Format("%d",time.GetYear());
      CDialog::OnOK();
      }

      Steve

      J Offline
      J Offline
      Jose Luis Sogorb
      wrote on last edited by
      #3

      Same error.

      S 1 Reply Last reply
      0
      • J Jose Luis Sogorb

        Same error.

        S Offline
        S Offline
        Steve Mayfield
        wrote on last edited by
        #4

        I assume that you have already set your CDateTimeCtrl with a value in your dialog using the SetTime method. I use virtually the same sequence in a filtering dialog and it works perfectly. Steve

        J 1 Reply Last reply
        0
        • S Steve Mayfield

          I assume that you have already set your CDateTimeCtrl with a value in your dialog using the SetTime method. I use virtually the same sequence in a filtering dialog and it works perfectly. Steve

          J Offline
          J Offline
          Jose Luis Sogorb
          wrote on last edited by
          #5

          No, the value in the dialog appears automatically(actual date), so I thought it was not needed to init with a value. How do you do it?

          S 1 Reply Last reply
          0
          • J Jose Luis Sogorb

            No, the value in the dialog appears automatically(actual date), so I thought it was not needed to init with a value. How do you do it?

            S Offline
            S Offline
            Steve Mayfield
            wrote on last edited by
            #6

            Is it possible that your control is a 'time only' control (check the dialog properties Styles/Format)? According to the docs, you will get an assert trying to access the date members in debug mode. Otherwise you need to set the style in the Create function. Steve

            J 1 Reply Last reply
            0
            • S Steve Mayfield

              Is it possible that your control is a 'time only' control (check the dialog properties Styles/Format)? According to the docs, you will get an assert trying to access the date members in debug mode. Otherwise you need to set the style in the Create function. Steve

              J Offline
              J Offline
              Jose Luis Sogorb
              wrote on last edited by
              #7

              No, I have it setted as 'short date' style. Can you give me an example code as you have initialized it? Thanks

              S 1 Reply Last reply
              0
              • J Jose Luis Sogorb

                No, I have it setted as 'short date' style. Can you give me an example code as you have initialized it? Thanks

                S Offline
                S Offline
                Steve Mayfield
                wrote on last edited by
                #8

                in the View Class:
                ...
                CDateTimeDlg dlg;
                CTime timeNewDateTime;

                dlg.m_DateTime = CTime::GetCurrentTime();
                if(dlg.DoModal() == IDOK)
                timeNewDateTime = dlg.m_DateTime;

                ======================
                in the CDateTimeDlg class:
                in the .h file:
                ...
                public:
                CDateTimeDlg(CWnd *pParent = NULL); // standard constructor
                CTime m_DateTime;
                // Dialog Data
                //{{AFX_DATA(CDateTimeDlg)
                enum { IDD = IDD_DATETIME_DLG };
                CDateTimeCtrl m_cDateTime;
                //}}AFX_DATA

                in the .cpp file:
                ...
                void CDateTimeDlg::DoDataExchange(CDataExchange* pDX)
                {
                CDialog::DoDataExchange(pDX);
                //{{AFX_DATA_MAP(CDateTimeDlg)
                DDX_Control(pDX, IDC_DATETIME, m_cDateTime);
                //}}AFX_DATA_MAP
                }

                BEGIN_MESSAGE_MAP(CDateTimeDlg, CDialog)
                //{{AFX_MSG_MAP(CDateTimeDlg)
                ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIME, OnDatetimechangeDateTime)
                //}}AFX_MSG_MAP
                END_MESSAGE_MAP()
                ...
                BOOL CDateTimeDlg::OnInitDialog()
                {
                CDialog::OnInitDialog();

                m_cDateTime.SetFormat("MM/dd/yyyy HH:mm:ss");
                m_cDateTime.SetTime(&m_DateTime);
                return TRUE; // return TRUE unless you set the focus to a control
                // EXCEPTION: OCX Property Pages should return FALSE
                }

                void CDateTimeDlg::OnDatetimechangeDateTime(NMHDR *pNMHDR, LRESULT *pResult)
                {
                m_cDateTime.GetTime(m_DateTime);
                *pResult = 0;
                }

                Steve

                J 2 Replies Last reply
                0
                • S Steve Mayfield

                  in the View Class:
                  ...
                  CDateTimeDlg dlg;
                  CTime timeNewDateTime;

                  dlg.m_DateTime = CTime::GetCurrentTime();
                  if(dlg.DoModal() == IDOK)
                  timeNewDateTime = dlg.m_DateTime;

                  ======================
                  in the CDateTimeDlg class:
                  in the .h file:
                  ...
                  public:
                  CDateTimeDlg(CWnd *pParent = NULL); // standard constructor
                  CTime m_DateTime;
                  // Dialog Data
                  //{{AFX_DATA(CDateTimeDlg)
                  enum { IDD = IDD_DATETIME_DLG };
                  CDateTimeCtrl m_cDateTime;
                  //}}AFX_DATA

                  in the .cpp file:
                  ...
                  void CDateTimeDlg::DoDataExchange(CDataExchange* pDX)
                  {
                  CDialog::DoDataExchange(pDX);
                  //{{AFX_DATA_MAP(CDateTimeDlg)
                  DDX_Control(pDX, IDC_DATETIME, m_cDateTime);
                  //}}AFX_DATA_MAP
                  }

                  BEGIN_MESSAGE_MAP(CDateTimeDlg, CDialog)
                  //{{AFX_MSG_MAP(CDateTimeDlg)
                  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIME, OnDatetimechangeDateTime)
                  //}}AFX_MSG_MAP
                  END_MESSAGE_MAP()
                  ...
                  BOOL CDateTimeDlg::OnInitDialog()
                  {
                  CDialog::OnInitDialog();

                  m_cDateTime.SetFormat("MM/dd/yyyy HH:mm:ss");
                  m_cDateTime.SetTime(&m_DateTime);
                  return TRUE; // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
                  }

                  void CDateTimeDlg::OnDatetimechangeDateTime(NMHDR *pNMHDR, LRESULT *pResult)
                  {
                  m_cDateTime.GetTime(m_DateTime);
                  *pResult = 0;
                  }

                  Steve

                  J Offline
                  J Offline
                  Jose Luis Sogorb
                  wrote on last edited by
                  #9

                  Thank you, very much. I'll try it.

                  1 Reply Last reply
                  0
                  • S Steve Mayfield

                    in the View Class:
                    ...
                    CDateTimeDlg dlg;
                    CTime timeNewDateTime;

                    dlg.m_DateTime = CTime::GetCurrentTime();
                    if(dlg.DoModal() == IDOK)
                    timeNewDateTime = dlg.m_DateTime;

                    ======================
                    in the CDateTimeDlg class:
                    in the .h file:
                    ...
                    public:
                    CDateTimeDlg(CWnd *pParent = NULL); // standard constructor
                    CTime m_DateTime;
                    // Dialog Data
                    //{{AFX_DATA(CDateTimeDlg)
                    enum { IDD = IDD_DATETIME_DLG };
                    CDateTimeCtrl m_cDateTime;
                    //}}AFX_DATA

                    in the .cpp file:
                    ...
                    void CDateTimeDlg::DoDataExchange(CDataExchange* pDX)
                    {
                    CDialog::DoDataExchange(pDX);
                    //{{AFX_DATA_MAP(CDateTimeDlg)
                    DDX_Control(pDX, IDC_DATETIME, m_cDateTime);
                    //}}AFX_DATA_MAP
                    }

                    BEGIN_MESSAGE_MAP(CDateTimeDlg, CDialog)
                    //{{AFX_MSG_MAP(CDateTimeDlg)
                    ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIME, OnDatetimechangeDateTime)
                    //}}AFX_MSG_MAP
                    END_MESSAGE_MAP()
                    ...
                    BOOL CDateTimeDlg::OnInitDialog()
                    {
                    CDialog::OnInitDialog();

                    m_cDateTime.SetFormat("MM/dd/yyyy HH:mm:ss");
                    m_cDateTime.SetTime(&m_DateTime);
                    return TRUE; // return TRUE unless you set the focus to a control
                    // EXCEPTION: OCX Property Pages should return FALSE
                    }

                    void CDateTimeDlg::OnDatetimechangeDateTime(NMHDR *pNMHDR, LRESULT *pResult)
                    {
                    m_cDateTime.GetTime(m_DateTime);
                    *pResult = 0;
                    }

                    Steve

                    J Offline
                    J Offline
                    Jose Luis Sogorb
                    wrote on last edited by
                    #10

                    It works fine in debug mode, also. Thanks!!!!

                    S 1 Reply Last reply
                    0
                    • J Jose Luis Sogorb

                      It works fine in debug mode, also. Thanks!!!!

                      S Offline
                      S Offline
                      Steve Mayfield
                      wrote on last edited by
                      #11

                      Happy to have helped you solve your problem. Steve

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups