Sorry, but that points out having the wrong idea about DODEFAULT()/NODEFAULT. No matter what you already understand about it, but there is no single default method of a control you call from anywhere with DODEFAULT() or suppress from anywhere with NODEFAULT, that points out you have established the idea from only ever seeing this in the context of a few events of classes like KeyPress() of a TextBox.
DODEFAULT() and NODEFAULT are acting about the
same method or event they are called in, just in
parent or base class level, so this isn't about recursive self calls nor about calling one specific default method. Maybe try to remember having seen NODEFAULT in other contexts of the TextBox, too, like using it in InteractiveChange() or GotFocus(). That then suppresses those events base behavior, not KeyPRess.
Let's start with NODEAULT, as that is only controlling the base class behavior of this method or event. The base class behavior surely also is code, but C++ and not VFP language code, you never see it but, of course, just as one example, a KeyPress event does handle keyboard input and changes the control value even without your help with any of your code just from the C++ code Microsoft did for the TextBox. With NODEFAULT you can suppress that behavior, ie putting just NODEFAULT in Keypress of a TextBox would render that TextBox to a read-only control.
NODEFAULT only suppresses base class code, not your code. NODEFAULT never plays a role in suppressing user-defined code, even if you use the base class TextBox on a form NODEAULT is not becoming self-referential.
DODEFAULT() is concerned with the next level parent class code and that parent class level is the base class level when you put a base class TextBox control on a form. In general, it's not calling the base TextBox behavior, when you have designed your own control based on the Textbox, DODEFAULT() merely executes what you defined in your own class, which in turn could call DODEFAULT() to call the base class or NODEFAULT to suppress it. I'm sure you'll find an example of that posted by me if you use the search of this forum.
But to see what this means for the simple case of a base class Texboxt on a form, we can try any combination and order of execution of NODEFAULT and DODEFAULT() and see what they do:
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
This is what you see in KeyPress method in the class code editor when you do nothing to it. The empty event means just running base behavior. So running a TextBox with no code in KeyPress the TextBox acts normal, you don't influence it at all.
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
NODEFAULT
As already said this causes the TextBox to act read-only. Almost. You can copy a text into the clipboard and act on the TextBox with CTRL+V, pasting the text into it. That global Windows keyboard shortcut is not processed by the Keypress, you don't get a KeyPress event. It's just a side note, as this is not about NODEFAULT and DODEFAULT() at all, but obviously, it could puzzle you when you'd like to intercept that from happening.
Another thing to note is that the base TextBox.Keypress() behavior is not executed before your KeyPress() code. Otherwise, your NO DEFAULT could never work and hinder this base behavior.
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
NODEFAULT
DODEFAULT(nKeyCode, nShiftAltCtrl)
-OR-
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
DODEFAULT(nKeyCode, nShiftAltCtrl)
NODEFAULT
In both cases, you get back to the normal TextBox behavior and it doesn't matter if you first state you want to suppress base class behavior and then execute it yourself anyway or first execute it yourself and then suppress it. As already said the default behavior is not yet run and NODEFAULT suppresses it from running. The first variant doing NODEFAULT illustrates, that the suppressing doesn't mean a total lock of this event where DODEFAULT() of the base behavior would also do nothing, the default behavior can still always be called, no matter if NODEFAULT already was executed or will be executed.
And the last code variant is
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
DODEFAULT(nKeyCode, nShiftAltCtrl)
DODEFAULT() means you explicitly call the base behavior here, as the parent of the Textbox object on the form is the Textbox base class. So that base behavior now runs twice that way because you don't suppress the standard call of it after your code already ran, so you get all keyboard input twice.
And to conclude about the Keypress example; You can override only some cases of nKeyCode, nShiftAltCtrl by executing NODEFAULT in an IF statement, it only acts as suppressor when executed.
Bye, Olaf.
Olaf Doschke Software Engineering