VC 不同对话框类中的数据访问有关问题
VC 不同对话框类中的数据访问问题
我在主对话框类里定义了个变量,然后让子对话框写数据给它,再在主对话框里读
代码如下:
CConfigDlg为子对话框
现在运行时会遇到错误:
Debug Assertion Failed!
Program:***.exe
File:wincore.cpp
Line:1085
For information on how your program can cause an assertionfailure,see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
------解决方案--------------------
在子对话框里面关联一个该控件变量的CString m_strPort;
再在对话框增加一个函数(Public)
Public :
CString GetPort(){ return m_strPort;}
void CMyProjectDlg::OnConfig()
{
// TODO: Add your control notification handler code here
CConfigDlg dlg;
CString strPort;
if(dlg.DoModal()==IDOK) // Ok时,要UpdateData(True)或UpdateData();
{
strPort = dlg.GetPort();
// dlg.m_edit1.GetWindowText(port);
}
}
------解决方案--------------------
CConfigDlg dlg;
在CConfigDlg类中定义一个变量:
m_port ;
在CConfigDlg类的IDOK响应函数中
m_edit1.GetWindowText(m_port );
这里你还可以做无效等值的判断
然后
void CMyProjectDlg::OnConfig()
{
// TODO: Add your control notification handler code here
CConfigDlg dlg;
CString port;
if(dlg.DoModal()==IDOK)
{
port = dlg.m_port;
}
}
我在主对话框类里定义了个变量,然后让子对话框写数据给它,再在主对话框里读
代码如下:
- C/C++ code
void CMyProjectDlg::OnConfig() { // TODO: Add your control notification handler code here CConfigDlg dlg; CString port; if(dlg.DoModal()==IDOK) { dlg.m_edit1.GetWindowText(port); } }
CConfigDlg为子对话框
现在运行时会遇到错误:
Debug Assertion Failed!
Program:***.exe
File:wincore.cpp
Line:1085
For information on how your program can cause an assertionfailure,see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
------解决方案--------------------
在子对话框里面关联一个该控件变量的CString m_strPort;
再在对话框增加一个函数(Public)
Public :
CString GetPort(){ return m_strPort;}
void CMyProjectDlg::OnConfig()
{
// TODO: Add your control notification handler code here
CConfigDlg dlg;
CString strPort;
if(dlg.DoModal()==IDOK) // Ok时,要UpdateData(True)或UpdateData();
{
strPort = dlg.GetPort();
// dlg.m_edit1.GetWindowText(port);
}
}
------解决方案--------------------
CConfigDlg dlg;
在CConfigDlg类中定义一个变量:
m_port ;
在CConfigDlg类的IDOK响应函数中
m_edit1.GetWindowText(m_port );
这里你还可以做无效等值的判断
然后
void CMyProjectDlg::OnConfig()
{
// TODO: Add your control notification handler code here
CConfigDlg dlg;
CString port;
if(dlg.DoModal()==IDOK)
{
port = dlg.m_port;
}
}