Solved

COleDateTime

Posted on 2003-12-01
17
1,367 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 40 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 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