?
Solved

COleDateTime

Posted on 2003-12-01
17
Medium Priority
?
1,372 Views
Last Modified: 2013-11-20
Hi

I am having some difficulty with the COleDateTime class in that I have a
DateTimePicker ctrl (m_date) and I am trying to initialise
it to the current time. from msdn help I have

DoDataExchange
DDX_DateTimeCtrl(pDX, IDC_LOG_DATE_PICKER, m_date);

Dialog Init
m_date = COleDateTime::GetCurrentTime();


Every time the dialog loads I get an error about "winCtrl5.cpp". I have traced it
and the above line is causing the problem.

Why? I had this working on Friday!


arrrghghghgh!!

Thanks in advance
LittlePerson
0
Comment
Question by:LittlePerson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
17 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9851005
Rebuild all option on build menu.  Does that cure it?
0
 

Author Comment

by:LittlePerson
ID: 9851023
Nope, I just realised that the assertion comes in Debg mode, in Release mode
everything seems to be fine. That must be why it was working and then not!

Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9851050
It shouldn't ASSERT in debug mode - after all that is what one uses to test the program and if it fails in debug it is probably unstable at best in release mode, at worst dangerous to the OP system.  
Rebuild all.  Put breakpoint and step in to see what exactly is ASSERTing.
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

Author Comment

by:LittlePerson
ID: 9851059
m_date = COleDateTime::GetCurrentTime();


this is the line that is asserting
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9855629
Put this code (m_date = COleDateTime::GetCurrentTime();
) in the Constructor of the Dialog instead of InitDialog. Otherwise *DoDataExchange* might make problems
0
 

Author Comment

by:LittlePerson
ID: 9856986
sorry for misleading but the code is in the Constructor!
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9857002
which line of "winCtrl5.cpp" is giving error...??
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9857029
Ohh yes thatz the problem...!!! put that in OnInitDialog

Why becoz, in the time of construction (dialog) the window handle will be invalid, only after the Create statement (after this function , OnInitDialog will take place). So the DateTime control is not cretaed..

Put this code (m_date = COleDateTime::GetCurrentTime();) code in OnInitDialog will solve the problem

Good Luck
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9857061
m_dte is a variable or the line in DoDataExchange
DDX_DateTimeCtrl(pDX, IDC_LOG_DATE_PICKER, m_date);
is wrong.
One can set the value in the ctor.

LittlePersin, have you stepped into the code yet to see where the ASSERT is?
0
 

Author Comment

by:LittlePerson
ID: 9857080

ASSERT is in "winCtrl5.cpp" line 189

I get assert in constructor at line

m_date = COleDateTime::GetCurrentTime();


i.e.

CSomeDialog dlg;

Stepping in here fires up constructor and bang!

Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9857169
The DoDataExchange macro
DDX_Control
will map a control variable (CDateTimeCtrl) to a resource ID

the macro you use
DDX_DateTimeCtrl
will map a variable (eg. COleDateTime) to a resource ID

I think you have got them mixed up.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9857177
If you are using a COleDateTimeCtrl variable you also set the contents with m_ctl.SetTime(COleDateTime::GetCurrentTime());
0
 

Author Comment

by:LittlePerson
ID: 9861548
I think something else is up. I took the following code and
put it in the InitDialog function. I got the same assertion

COleDateTime dtCurrent;
dtCurrent = COleDateTime::GetCurrentTime();
AfxMessageBox(dtCurrent.Format("Today is %a %b %d, %Y"));


What gives?

Seriously confused
0
 

Author Comment

by:LittlePerson
ID: 9861645
also it is definitely working in release mode!!!
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 160 total points
ID: 9864938
WinCtrl5.cpp line 189 is (at least my copy)
            ASSERT(timeDest.GetStatus() == COleDateTime::valid);


Or rather
BOOL CDateTimeCtrl::GetTime(COleDateTime& timeDest) const
{
      SYSTEMTIME sysTime;
      BOOL bRetVal = TRUE;

      LRESULT result = ::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM) &sysTime);
      if (result == GDT_VALID)
      {
            timeDest = COleDateTime(sysTime);
            bRetVal = TRUE;
            ASSERT(timeDest.GetStatus() == COleDateTime::valid);
      }
      else if (result == GDT_NONE)
      {
            timeDest.SetStatus(COleDateTime::null);
            bRetVal = TRUE;
      }
      else
            timeDest.SetStatus(COleDateTime::invalid);
      return bRetVal;
}

How a COleDateTime variable is calling a CDateTimeCtrl function I don't understand at all.



Try removing your variable with the class wizard, rebuild then recreate your variable with the class wizard, rebuild again and see if it still crashes.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10711610
?
refund points and accept AndyAinscow
Error !!!!

<refund is OK by me>
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question