-
Assertion Failed!
Help!
I have create Dialog Application with MS VC++.
I have added a new Dialog (CHelp) resourse which contains a text box. The dialog is invoked from the main menu bar.
I have mapped the textbox to a member variable of CHelp.
I have added a member function to CHelp which takes a string and displays it in the text box. However, when this function is invoked i get "DEBUG Assertion Error" If I change the active configuration to release, then nothing is displayed.
Whats wrong?
Code:
Code.....
CDialog Class (Main app class)
void CCadFTPDlg::OnHelp()
{
CHelp help;
help.loadHelpText();
help.DoModal();
}
//----------------------
CHelp : public CDialog Class...
void CHelp::loadHelpText(CString str)
{
m_helptext.SetWindowText(str);
}
-
> when this function is invoked i get "DEBUG Assertion Error"
Then read what it says very carefully. The text should at least hint as to what you're doing wrong. If its something like "hWnd!=NULL" then it means you passed a hWnd of NULL to it, and that would be wrong.
> If I change the active configuration to release, then nothing is displayed.
Assertions are only in debug builds, you're still passing incorrect values to the function, only you don't realise it. Whether it works now, then there is a good chance that something else will stop working later.
-
The only clue given by the error dialog is
winocc.cpp
-
Initialize your help text inside of OnInitDialog(). This is called just after the dialog is created and just before it is displayed. All data init for objects should be done in this function.
You are setting the text before CHelp is a valid dialog box object.
Even though CHelp is an object, the dialog box resource is not valid until you call DoModal. At that time the dialog box object is created from the resource and then OnInitDialog() is called just prior to displaying it. This is why you need to init all your data inside of this function.
Code:
void CMainFrame::OnHelpText()
{
CDialog Help(this);
CString text;
text="Testing 123";
Help.SetWindowText(text);
}