Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

COleDateTime

Posted on 2003-12-01
17
Medium Priority
?
1,376 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 45

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 45

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
Independent Software Vendors: 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 45

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 45

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 45

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 45

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 45

Expert Comment

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

<refund is OK by me>
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

609 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