输入密码后在执行程序出错
没有用进程,程序想实现的是功能是:用户删除某条记录时跳出一个form要求输入密码,点击确认后form关闭,如果密码正确,记录允许删除,如果不正确,form再次跳出;
我的方法是在form1中设了个全局变量为mm(密码),用户删除记录时form2采用ShowModal()的方式弹出,输入密码点击确认后,在form2的按钮事件中我是这样写的:
Form1->mm = edt1->Text;
this->Close();
Form1->N1Click(Application);//返回到form1中的删除按钮;
if(mm == "123")
{...}
else
{
form2->ShowModal();
}
void CheckPassword(const char *szPassword) {
TFormCheckPassword *form = new TFormCheckPassword(this, szPasswsord);
do {
form->ShowModal();
} while ( !form->PasswordOk() );
delete form;
}
TFromCheckPassword : public TForm {
private :
char m_szPassword[MAX_PASSWORD_LEN];
bool m_bPasswordOk;
public :
TFromCheckPassword(TComponent *Owner, const char *p_szPassword);
bool PasswordOk() { return m_bPasswordOk; }
....
};
void TFormCheckPassword::bnOkClick(.... ) {
m_bPasswordOk = strcmp(m_szPassword, edPassword->Text.t_str()) == 0;
if ( m_bPasswordOk )
ModalResult = mrOk;
else {
MessageBox(this->Handle, "密码错误", "提示", MB_OK
[解决办法]
MB_EXCLAMATION);
edPassword->SetFocus();
}