运行老出现Assertion Failed。

xin520hua 2009-06-01 02:57:20
各位朋友,我在EVC下写了这样一个程序,编译能通过,但运行是老 出现Assertion Failed这个错误。
程序是这样的:
我建了一个对话框的程序:
首先点按钮生成一个对话框 CDlgEdit:
void CManeger007Dlg::OnBtnadd()
{
// TODO: Add your control notification handler code here
m_operID = 0;//注释掉后程序可运行
CDlgEdit Dlg(this);//注释掉后程序可运行
Dlg.DoModal();//注释掉后程序可运行
}
然后我在生成的对框的按钮时又添加了如下代码:
void CDlgEdit::OnBtnsave()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);

// 以下代码用于把时间提出出来,放到结构体中
alarm alarmtime;
CTime time;
time = m_time1.GetTime(time);
alarmtime.m_year = time.GetYear();
alarmtime.m_month = time.GetMonth();
alarmtime.m_day = time.GetDay();
time = m_time2.GetTime(time);
alarmtime.m_year = time.GetHour();
alarmtime.m_month = time.GetMinute();
alarmtime.m_day = time.GetSecond();
// 以上代码用于把时间提出出来放到结构体中


bool operID = ((CManeger007Dlg*)GetParent())->m_operID;
if(operID == 0)
{ //是添加操作,要建立一个新文件
UpdateData(TRUE);
CString contents,topic,filename;
topic = m_topic; //保存输入的文件名,也就是主题
topic += ".dat"; //完整的文件名+.dat
filename= "\\My Documents\\" ;
filename += topic; //路径名+文件名
contents = m_contents;
TCHAR array [100];
wcscpy(array,contents); // 把内容转化成数组,以便保存。


CFile file;
file.Open(filename,CFile::modeCreate | CFile::modeWrite);
file.Write(&alarmtime,sizeof(alarmtime)); //把时间保存
file.Write(array,100); //保存内容
((CManeger007Dlg*)GetParent())->m_ListTopic.AddString(topic);

this->EndDialog(0); // 关闭对话框
}
else
{ //是编辑操作



}

}

大概的代码就是这样的,这是怎么回事啊?我刚学这东西,调试还不会。
...全文
817 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
meimi 2010-12-06
  • 打赏
  • 举报
回复
太谢谢了,我也是没把关联变量删掉,万分感谢,终于在绝望中看到了希望了,谢谢楼主
ggmfc 2009-06-02
  • 打赏
  • 举报
回复
学习了!
oyljerry 2009-06-01
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 xin520hua 的回复:]
找出错误的所在了,0x03F1这个编辑框不存在了,我还给他关联了一个变量,因而在
DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgEdit)
DDX_Control(pDX, IDC_DATETIMEPICKER2, m_time2);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_time1);
DDX_Text(pDX, IDC_EDITTOPIC, m_topic);
DDX_Text(pDX, IDC_EDITCONTENTS, m_contents);
DDX_Text(pDX, IDC_EDIT1…
[/Quote]
这种情况多数是资源修改的时候引起的,比如拷贝控件等,从而控件ID不对,这样绑定控件的时候就会出错
xin520hua 2009-06-01
  • 打赏
  • 举报
回复
找出错误的所在了,0x03F1这个编辑框不存在了,我还给他关联了一个变量,因而在
DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgEdit)
DDX_Control(pDX, IDC_DATETIMEPICKER2, m_time2);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_time1);
DDX_Text(pDX, IDC_EDITTOPIC, m_topic);
DDX_Text(pDX, IDC_EDITCONTENTS, m_contents);
DDX_Text(pDX, IDC_EDIT1, m_test);//多出的。
}

会到class wizard删掉关联的变量,程序就能正常运行了。
xin520hua 2009-06-01
  • 打赏
  • 举报
回复
提示是断言错误,Error: no data exchange control with ID 0x03F1.这个东东究竟是个什么?
没数据交换控件?
zteclx 2009-06-01
  • 打赏
  • 举报
回复
断言错误
xin520hua 2009-06-01
  • 打赏
  • 举报
回复
高人帮忙啊,我实在是找不出来这个东东究竟是什么原因
xin520hua 2009-06-01
  • 打赏
  • 举报
回复
SENDING command id 0x03E9 to CDialog target.
Error: no data exchange control with ID 0x03F1.
Assertion Failed: Maneger007: File dlgdata.cpp, Line 52,我刚刚运行了下,发现了这个提示。
  • 打赏
  • 举报
回复
看一下call stack
xin520hua 2009-06-01
  • 打赏
  • 举报
回复
运行后点击按钮后,出现如下错误:一个对话框
Maneger007: File dlgdata.ccp,line
同时还有 三个 按钮:abort rety ingore
xin520hua 2009-06-01
  • 打赏
  • 举报
回复
哪位朋友看下错误出在哪里。我用的是EVC,调试我不怎么会,郁闷了。
xin520hua 2009-06-01
  • 打赏
  • 举报
回复
工程名叫Maneger007
typedef struct _affairtime
{
int m_year;
int m_month;
int m_day;
int m_hours;
int m_minute;
int m_second;
} alarm;//定义的用来保存时间的。

class CManeger007Dlg : public CDialog
{
// Construction
public:
CManeger007Dlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CManeger007Dlg)
enum { IDD = IDD_MANEGER007_DIALOG };
CListBox m_ListTopic;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CManeger007Dlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
HICON m_hIcon;
public:
bool m_operID;

// Generated message map functions
//{{AFX_MSG(CManeger007Dlg)
virtual BOOL OnInitDialog();
afx_msg void OnBtnbrowse();//按钮
afx_msg void OnBtnadd();//按钮
afx_msg void OnBtndelete();//按钮
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

BOOL CManeger007Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

CenterWindow(GetDesktopWindow()); // center to the hpc screen

// TODO: Add extra initialization here

// 首先把 \My Documents 这个文件夹中的“*.dat”类型的文件的文件名添加到m_ListTopic中

//测试代码

// CFile file;
// file.Open(_T("\\My Documents\\hello.dat"),CFile::modeCreate | CFile::modeWrite);

WIN32_FIND_DATA filedata;
HANDLE handle;
handle = FindFirstFile(_T("\\My Documents\\*.*"),&filedata);
bool flag;
if( handle == INVALID_HANDLE_VALUE )
{
//MessageBox(_T("find failure"));
return FALSE;
}
else
{
do
{
if(!(filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
unsigned short *p;
p=wcsrchr(filedata.cFileName, '.');
*p = 0;
m_ListTopic.AddString(filedata.cFileName);
}

flag = (bool)FindNextFile(handle,&filedata);

}
while(flag);
FindClose(handle);
}


return TRUE; // return TRUE unless you set the focus to a control
}

void CManeger007Dlg::OnBtnbrowse()
{
// TODO: Add your control notification handler code here
m_operID = 1;
CDlgEdit Dlg(this);


Dlg.DoModal();


}

void CManeger007Dlg::OnBtnadd()
{
// TODO: Add your control notification handler code here
m_operID = 0;
CDlgEdit Dlg(this);
Dlg.DoModal();
}

void CManeger007Dlg::OnBtndelete()
{
// TODO: Add your control notification handler code here

}

void CManeger007Dlg::OnOK()
{
// TODO: Add extra validation here

//CDialog::OnOK(); // 按回车不关闭程序
}


class CDlgEdit : public CDialog
{
// Construction
public:
CDlgEdit(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CDlgEdit)
enum { IDD = IDD_DIALOG1 };
CDateTimeCtrl m_time2;
CDateTimeCtrl m_time1;
CString m_topic;
CString m_contents;
CString m_test;
//}}AFX_DATA

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDlgEdit)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:

// Generated message map functions
//{{AFX_MSG(CDlgEdit)
virtual void OnOK();
afx_msg void OnBtnedit();
afx_msg void OnBtncancle();
afx_msg void OnBtnsave();
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CDlgEdit::CDlgEdit(CWnd* pParent /*=NULL*/)
: CDialog(CDlgEdit::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgEdit)
m_topic = _T("");
m_contents = _T("");
m_test = _T("");
//}}AFX_DATA_INIT
}


void CDlgEdit::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgEdit)
DDX_Control(pDX, IDC_DATETIMEPICKER2, m_time2);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_time1);
DDX_Text(pDX, IDC_EDITTOPIC, m_topic);
DDX_Text(pDX, IDC_EDITCONTENTS, m_contents);
DDX_Text(pDX, IDC_EDIT1, m_test);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgEdit, CDialog)
//{{AFX_MSG_MAP(CDlgEdit)
ON_BN_CLICKED(IDC_BTNEDIT, OnBtnedit)
ON_BN_CLICKED(IDC_BTNCANCLE, OnBtncancle)
ON_BN_CLICKED(IDC_BTNSAVE, OnBtnsave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgEdit message handlers

void CDlgEdit::OnOK()
{
// TODO: Add extra validation here

//CDialog::OnOK(); //仅为了按回车不关闭程序
}

void CDlgEdit::OnBtnedit()
{
// TODO: Add your control notification handler code here

}

void CDlgEdit::OnBtncancle()
{
// TODO: Add your control notification handler code here

}

void CDlgEdit::OnBtnsave()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);

// 以下代码用于把时间提出出来
alarm alarmtime;
CTime time;
time = m_time1.GetTime(time);
alarmtime.m_year = time.GetYear();
alarmtime.m_month = time.GetMonth();
alarmtime.m_day = time.GetDay();
time = m_time2.GetTime(time);
alarmtime.m_year = time.GetHour();
alarmtime.m_month = time.GetMinute();
alarmtime.m_day = time.GetSecond();
// 以上代码用于把时间提出出来


bool operID = ((CManeger007Dlg*)GetParent())->m_operID;
if(operID == 0)
{ //是添加操作,要建立一个新文件
UpdateData(TRUE);
CString contents,topic,filename;
topic = m_topic; //保存输入的文件名,也就是主题
topic += ".dat"; //完整的文件名+.dat
filename= "\\My Documents\\" ;
filename += topic; //路径名+文件名
contents = m_contents;
TCHAR array [100];
wcscpy(array,contents); // 把内容转化成数组,以便保存。


CFile file;
file.Open(filename,CFile::modeCreate | CFile::modeWrite);
file.Write(&alarmtime,sizeof(alarmtime)); //把时间保存
file.Write(array,100); //保存内容
((CManeger007Dlg*)GetParent())->m_ListTopic.AddString(topic);

this->EndDialog(0); // 关闭对话框
}
else
{ //是编辑操作



}

}

BOOL CDlgEdit::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here



return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}



yeman039 2009-06-01
  • 打赏
  • 举报
回复
我把整段代码贴出来,大家再帮我看看。
lyx_wq 2009-06-01
  • 打赏
  • 举报
回复
设断点 跟踪调试
supeng411 2009-06-01
  • 打赏
  • 举报
回复
也有可能是资源id冲突
dch4890164 2009-06-01
  • 打赏
  • 举报
回复
看一下callstack找到具体断言的代码,自己调这种程序会比较有收获
bofrobber 2009-06-01
  • 打赏
  • 举报
回复
感觉应该是那个file.Open出的错
你用了相对路径,那个相对路径本身不存在,文件创建会有问题,
另外,提一点,文件打开后,需要关闭操作。
vcTiro 2009-06-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bxf19830819 的回复:]
简单的调试一下,定位错误位置

简单调试一下是很容易的,找点资料看看,要不然别人都不好帮你
[/Quote]

94。LZ最好把那个断言对话框上的信息看清楚! 这就是很简单的事情,要不贴出来也可。
峰白 2009-06-01
  • 打赏
  • 举报
回复
简单的调试一下,定位错误位置

简单调试一下是很容易的,找点资料看看,要不然别人都不好帮你

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧