MFC question -- updation problem
HI,
There are two classes A and B as follows
class A
{
public:
update_host(CString hostname);
}
class B
{
public:
get_hostname();
}
The get_hostname() gets the hosts name and then calls update_host as folows
A aobject;
aobject.update_host(CString hostname);
now this is what i do in update_host(CString hostname)
update_host(CString hostname)
{
m_hostname=hostname;
UpdateData(FALSE) //to update the value in the edit box.
}
now,when i execute it,i get the error saying
Debug assertion failed.
file:wincore.cpp
line:3095.
Please help in this regards.
Thank you.
Re: MFC question -- updation problem
Well...is class A derived from a dialog class? 'UpdateData()' needs the context of the dialog class in order to update values...
Re: MFC question -- updation problem
Yes,Exactly the class A is derived from dialog class.and i am using its context.then also i am getting error.
Re: MFC question -- updation problem
Where is the DoDataExchange function !
Re: MFC question -- updation problem
DoDataExchange function is in class B.
Re: MFC question -- updation problem
DoDataExchange must be in the class that calls UpdateData
Re: MFC question -- updation problem
From your code snippet I am guessing that A defines a dialog - if that's true, then the problem is:
Code:
The get_hostname() gets the hosts name and then calls update_host as folows
A aobject;
aobject.update_host(CString hostname);
now this is what i do in update_host(CString hostname)
update_host(CString hostname)
{
m_hostname=hostname;
UpdateData(FALSE) //to update the value in the edit box.
}
You have created an object (aobject) but at this point the window(s) have not been created. This happens when you call DoModal (or Create if modeless).
Until the windows exist, UpdateData will fail.
You'll need to update the windows after the call to CDialog::OnInitDialog inside your overridden OnInitDialog function.
Hope that helps.