This is obviously a hole in my self taught computer science education...
The constructor for a text control (wxTextCtrl) in a wxWidgets application has an optional parameter for a validator object. All of the code examples create the validator on the fly within the constructor for the text control.
This works..
wxString value = L"0.0";
wxTextCtrl* _Text = new wxTextCtrl(this, wxID_ANY, value,
wxDefaultPosition, wxDefaultSize, 0,
wxTextValidator(wxFILTER_NUMERIC, &value));
However in my particular case I want to create the validator in another function and pass it back, which isn't working. As an intermediate step I've tried to create it just before creating the wxTextCtrl and pass it in but that doesn't work either...
wxString value = L"0.0";
wxValidator valid = wxTextValidator(wxFILTER_NUMERIC, &value);
wxTextCtrl* _Text = new wxTextCtrl(this, wxID_ANY, value,
wxDefaultPosition, wxDefaultSize, 0, valid);
Although this compiles and runs it doesn't perform the validation. Can anyone explain why?
The prototype for the wxTextValidator calls for a constant reference..
wxTextCtrl::wxTextCtrl ( wxWindow * parent,
wxWindowID id,
const wxString & value = wxEmptyString,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = 0,
const wxValidator & validator = wxDefaultValidator,
const wxString & name = wxTextCtrlNameStr
)