在对话框里执行下面语句总是出现Debug Assertion Failed!而在视图类就很正常
class CGridDlg : public CDialog
{
public:
CMyDoc* GetDocument();
CMySet* m_pSet;
CGrid(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CGrid)
enum { IDD = IDD_GRID };
CMSFlexGrid m_MSFGrid;
}
BOOL CGridDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_pSet = &GetDocument()->m_mySet;
while(!m_pSet->IsEOF()) m_pSet->MoveNext();
m_pSet->MoveFirst();
m_MSFGrid.SetCols(m_pSet->m_nFields+1);
m_MSFGrid.SetRows(m_pSet->GetRecordCount()+1);
m_MSFGrid.SetRow(0); m_MSFGrid.SetCol(0);
m_MSFGrid.SetText("记录号");
m_MSFGrid.SetCellAlignment(4); //单元格对齐方式,4表示水平和垂直居中
CODBCFieldInfo field;
for (UINT i=0; i<m_pSet->m_nFields; i++)
{
m_MSFGrid.SetRow(0); m_MSFGrid.SetCol(i+1);
m_pSet->GetODBCFieldInfo(i,field); // 获取指定字段信息
m_MSFGrid.SetText(field.m_strName);
m_MSFGrid.SetCellAlignment(4);
}
int iRow=1;
while (!m_pSet->IsEOF())
{ // 将表的记录内容显示在单元格中
CString str;
str.Format("记录%d",iRow);
m_MSFGrid.SetRow(iRow); m_MSFGrid.SetCol(0);
m_MSFGrid.SetText(str);
m_MSFGrid.SetCellAlignment(4);
for (UINT i=0; i<m_pSet->m_nFields; i++)
{
m_MSFGrid.SetRow(iRow); m_MSFGrid.SetCol(i+1);
m_pSet->GetFieldValue(i, str); // 获取指定字段值,并自动转换成字符串
m_MSFGrid.SetText(str);
m_MSFGrid.SetCellAlignment(4);
}
iRow++;
m_pSet->MoveNext();
}
m_MSFGrid.SetRow(1); m_MSFGrid.SetCol(1);
m_pSet->MoveFirst();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
上面的初始化函数在View类里运行的很正常,但在我自定义的CGridDlg类里就出现Debug Assertion Failed
File:objcore.cpp Line:43
File:objcore.cpp Line:45
忽略这两个之后,Microsoft基础类应用程序服务已停止工作的对话框