fix crash if Delete menu command is used twice

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16969 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-09-04 13:50:58 +00:00
parent 8161b5b9f0
commit 798265916e

View File

@@ -220,11 +220,18 @@ void MyFrame::OnAbout(wxCommandEvent&)
void MyFrame::OnDelete(wxCommandEvent&) void MyFrame::OnDelete(wxCommandEvent&)
{ {
if ( wxConfigBase::Get()->DeleteAll() ) wxConfigBase *pConfig = wxConfigBase::Get();
if ( pConfig == NULL )
{
wxLogError(_T("No config to delete!"));
return;
}
if ( pConfig->DeleteAll() )
{ {
wxLogMessage(_T("Config file/registry key successfully deleted.")); wxLogMessage(_T("Config file/registry key successfully deleted."));
delete wxConfigBase::Set((wxConfigBase *) NULL); delete wxConfigBase::Set(NULL);
wxConfigBase::DontCreateOnDemand(); wxConfigBase::DontCreateOnDemand();
} }
else else
@@ -235,10 +242,11 @@ void MyFrame::OnDelete(wxCommandEvent&)
MyFrame::~MyFrame() MyFrame::~MyFrame()
{ {
// save the control's values to the config
wxConfigBase *pConfig = wxConfigBase::Get(); wxConfigBase *pConfig = wxConfigBase::Get();
if ( pConfig == NULL ) if ( pConfig == NULL )
return; return;
// save the control's values to the config
pConfig->Write("/Controls/Text", m_text->GetValue()); pConfig->Write("/Controls/Text", m_text->GetValue());
pConfig->Write("/Controls/Check", m_check->GetValue()); pConfig->Write("/Controls/Check", m_check->GetValue());
@@ -253,3 +261,4 @@ MyFrame::~MyFrame()
pConfig->Write("/TestValue", wxT("A test value")); pConfig->Write("/TestValue", wxT("A test value"));
} }