DateTimePicker error debugging
-
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
-
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
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
-
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
Same error.
-
Same error.
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
-
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
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?
-
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?
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
-
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
No, I have it setted as 'short date' style. Can you give me an example code as you have initialized it? Thanks
-
No, I have it setted as 'short date' style. Can you give me an example code as you have initialized it? Thanks
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_DATAin 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
-
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_DATAin 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
Thank you, very much. I'll try it.
-
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_DATAin 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
It works fine in debug mode, also. Thanks!!!!
-
It works fine in debug mode, also. Thanks!!!!
Happy to have helped you solve your problem. Steve