I've include a complete sample of my problem. This code compiles and runs fine. But if I uncomment the int y = text2->GetLineLength(0); statement, I will get a segmentation fault error. Anybody have any ideas on why this is happening and possibly a resolution?
Thanx
Code: Select all
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
class BasicPanel : public wxPanel
{
public:
BasicPanel(wxFrame* parent,int x, int y, int w, int h);
~BasicPanel( );
void OnTextEnter(wxCommandEvent& WXUNUSED(event));
wxTextCtrl *text1;
wxTextCtrl *text2;
DECLARE_EVENT_TABLE()
};
enum
{
Static_Text = wxID_HIGHEST+5000,
Text1Input,
Text2Input,
};
BEGIN_EVENT_TABLE(BasicPanel,wxPanel)
EVT_TEXT( wxID_ANY, BasicPanel::OnTextEnter )
END_EVENT_TABLE()
BasicPanel::BasicPanel(wxFrame* parent,int x, int y, int w, int h) : wxPanel(parent, wxID_ANY, wxPoint(x, y), wxSize(w, h) )
{
text1 = new wxTextCtrl(this, Text1Input, wxEmptyString, wxPoint(110, 20), wxSize(180, 30),wxTE_PROCESS_ENTER );
text1->SetMaxLength(23);
text1->SetFocus();
text1->SetValue("Text Control 1");
text2 = new wxTextCtrl(this, Text2Input, wxEmptyString, wxPoint(110, 60), wxSize(180, 30),wxTE_PROCESS_ENTER );
text2->SetMaxLength(23);
text2->SetValue("Text Control 2");
}
BasicPanel::~BasicPanel( ) {}
wxPanel *thePanel;
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title);
void OnQuit(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE()
};
enum
{
Minimal_Quit = wxID_EXIT,
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_T("wxWidgets wxTextCtrl bug App"));
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
thePanel = new BasicPanel(this, 0,100,300,330);
#if wxUSE_STATUSBAR
CreateStatusBar(2);
SetStatusText(_T("Possible wxTextCtrl bug"));
#endif
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void BasicPanel::OnTextEnter(wxCommandEvent& WXUNUSED(event))
{
int x = text1->GetLineLength(0);
// int y = text2->GetLineLength(0);
}