Solved

COleDateTime

Posted on 2003-12-01
17
1,352 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
string initialization in java 11 110
conditional code and condition difference 9 77
only14 challenge 19 69
Way to decrease size of apk file 9 45
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

896 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

13 Experts available now in Live!

Get 1:1 Help Now