Solved

COleDateTime

Posted on 2003-12-01
17
1,344 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
  • 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now