wxMSW2.8.3 - 'OnOK' : is not a member of 'wxDialog' ??
Carsten A. Arnholm
arnholm at offline.no
Tue Apr 17 16:38:37 PDT 2007
Bryan Petty wrote:
> Carsten A. Arnholm wrote:
>> I do not understand why I get this message, OnOK(wxCommandEvent&
>> event) is clearly a member function of 'wxDialog' ? I have checked
>> it several times. If I remove the call to wxDialog::OnOK(event); it
>> compiles, and I can break in the Settings::OnOK function, but
>> obviously the dialog does not close.
>
> OnOK isn't a member, it used to be in 2.6.3, but it was a mistake that
> it was there in the first place because it encouraged developers to
> abuse it like you did in your example. It was removed for 2.8.
>
> Please see the following links for more info (this subject has come up
> numerous times before, try searching first):
>
> http://wxforum.shadonet.com/viewtopic.php?t=11103
> http://wxforum.shadonet.com/viewtopic.php?t=10558
> http://wxforum.shadonet.com/viewtopic.php?t=11573
> http://thread.gmane.org/gmane.comp.lib.wxwidgets.devel/78984/focus=79043
>
> Regards,
> Bryan Petty
Ok, Many thanks for that. It does make things clearer. I wasn't aware of any
abuse.
However, I still somewhat puzzled by the fact that my 2.8.3 header file
wxWidgets-2.8.3\include\wx\univ\dialog.h clearly lists the functions
// event handlers
void OnCloseWindow(wxCloseEvent& event);
void OnOK(wxCommandEvent& event);
void OnApply(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
So somehow it is there and it isn't. I do accept it is not supposed to be
there :-) I guess there must be the platform specific code that has it
removed somehow.
What I read from your links is that the following pattern should work
void MyDialog::OnOk( wxCommandEvent &p_event ){
if( DoSomeSpecializedStuff() ) {
p_event.Skip();
}
}
It does work. However, the problem with this, as I see it, is that
DoSomeSpecializedStuff() typically needs to get access to the member
variables assiged to the dialog controls (that is why I make the handler),
but in this pattern they are not available or validated at the time
DoSomeSpecializedStuff() is called.
However, I tried this successfully:
void Settings::OnOK(wxCommandEvent& event)
{
// wxString txt = TextCtrl1->GetValue(); // this fails
event.Skip();
wxString txt = TextCtrl1->GetValue(); // extract value from dialog
control
}
Evaluating TextCtrl1->GetValue(); before event.Skip(); will not work, but
after it has completed it seems ok. Is this safe?
Thanks again
Carsten A. Arnholm
http://arnholm.org/
N59.776 E10.457
More information about the wx-users
mailing list