當試圖刪除或更改其值時,wxTextCtrl會導致一些內存分配問題。這裏有一些代碼見解:wxWidgets wxTextCtrl在刪除時崩潰
wxTextCtrl* s = new wxTextCtrl(...);
s->SetValue("abc");//crash
delete s//crash
它就像它的所有成員都是const的。這裏是VisualStudio中說什麼,當它崩潰:
An unhandled exception of type 'System.AccessViolationException'
occurred in Unknown Module.
Additional information: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
即使我嘗試wxWidgets的默認破壞:
parent->DestroyChildren(); //ofc the parent is wxPane passed in constructor of s
任何幫助將不勝感激。
下面是調用wxTextCtrl的唯一功能的一些實際代碼:調用的SetValue
void AddButton::OnAction(wxSize* frame){
if (!DoAction){
if (! thy)
{
thy = new wxPanel
(mParent, -1,
wxPoint(0, 0),
wxSize(PanelWidth, mParent->GetSize().GetHeight()),
wxBORDER_NONE | wxFRAME_FLOAT_ON_PARENT);
thy->SetBackgroundColour(wxColor(30,30,30));
thy->Show();
if (! AddPanelDialog){
//AddPanelDialog = (new _Text
//(this, thy, "add link...", wxPoint(1, 30), wxSize(PanelWidth - 30, 20),
//wxBORDER_NONE | wxTE_PROCESS_ENTER));
wxTextCtrl* s = new wxTextCtrl(thy, -1, "", wxPoint(1, 30), wxSize(PanelWidth - 30, 20),
wxBORDER_NONE | wxTE_PROCESS_ENTER);
s->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(_Text::OnEnter));
s->Show();
}
if (!ConfirmPanel){
ConfirmPanel = new wxPanel
(thy, -1, wxPoint(PanelWidth - 28, 30), wxSize(27, 20),
wxBORDER_NONE | wxFRAME_FLOAT_ON_PARENT);
ConfirmPanel->SetBackgroundColour(wxColor(38, 145, 232));
ConfirmPanel->Show();
}
}
else {
thy->Show();
}
gui* rmd = (gui*)mParent;
rmd->LeftPanelActivate();
rmd->SetNewPositions(rmd->GetParent()->GetSize());
Button::Update();
helper::SendRedrawEvent(mParent);
DoAction = true; // indicates action activated
}
else{
thy->Hide();
gui* rmd = (gui*)mParent;
rmd->LeftPanelActivate(false);
rmd->SetNewPositions(rmd->GetParent()->GetSize());
Button::Update();
helper::SendRedrawEvent(mParent);
DoAction = false; // indicates action activated
}
}
和功能()
void AddButton::OnEnter(wxCommandEvent& event)//enter button handler
{
wxTextCtrl* _t = (wxTextCtrl*)this;
_Clear();
*_t<<"sup";
}
在你的代碼的其他地方顯然存在一個錯誤,你必須明白,調用'SetValue()'不會崩潰,如果沒有其他地方沒有錯。但是你不會告訴我們關於你的其他代碼的任何信息,因此無法幫助你。 – 2013-03-17 23:13:22
@VZ。在那裏我添加了更多的代碼。我正在使用IMPLEMENT_APP宏實現該應用程序。其他一切都像往常一樣,因爲它可以是... – 2013-03-17 23:25:27