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 的唯一函数的一些实际代码:
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
}
}
和调用 SetValue() 的函数
void AddButton::OnEnter(wxCommandEvent& event)//enter button handler
{
wxTextCtrl* _t = (wxTextCtrl*)this;
_Clear();
*_t<<"sup";
}