我的文档视图结构程序中有一对话框,现我要在对话框中访问文档资源,怎么办,我是这样做的但不能运行:
.h文件中
CMainDoc* GetDocument();
。
。
。
#ifndef _DEBUG // debug version in LeftpaneFrame.cpp
inline CMainDoc* CSearchDlg::GetDocument()
{ return (CMainDoc*)m_pDocument; }
#endif
////////////////////////////////////////////////////////
。CPP文件中
#ifdef _DEBUG
CMainDoc* CSearchDlg::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMainDoc)));
return (CMainDoc*)m_pDocument;
}#endif //_DEBUG
///////////////////////////////////////////////////////////
我访问文档资源在对话框 的INITDIALOG中,
如:
BOOL CSearchDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_pList = GetDocument()->GetList();
。。
}
运行时通不过,我看了一下代码好像是在这里就不能通过: ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMainDoc)));怎么办呢?文档定义保证没有问题,因为我在视图中访问没有任何问题。谢谢各位很急!
.h文件中
CMainDoc* GetDocument();
。
。
。
#ifndef _DEBUG // debug version in LeftpaneFrame.cpp
inline CMainDoc* CSearchDlg::GetDocument()
{ return (CMainDoc*)m_pDocument; }
#endif
////////////////////////////////////////////////////////
。CPP文件中
#ifdef _DEBUG
CMainDoc* CSearchDlg::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMainDoc)));
return (CMainDoc*)m_pDocument;
}#endif //_DEBUG
///////////////////////////////////////////////////////////
我访问文档资源在对话框 的INITDIALOG中,
如:
BOOL CSearchDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_pList = GetDocument()->GetList();
。。
}
运行时通不过,我看了一下代码好像是在这里就不能通过: ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMainDoc)));怎么办呢?文档定义保证没有问题,因为我在视图中访问没有任何问题。谢谢各位很急!
CSdi2Doc * pDoc =(CSdi2Doc *) pMDIActive->GetActiveDocument();
#include "sdi2Doc.h"
CFrameWnd * pActive =((CFrameWnd*) AfxGetApp()->GetMainWnd())->GetActiveFrame();
m_pDocument = (CMainDoc*)pActive->GetActiveDocument();
m_pList = m_pDocument->GetList();
第二个应该变通