Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How And What Do The DODEFAULT() & NODEFAULT() Actually Do 3

Status
Not open for further replies.

drosenkranz

Programmer
Sep 13, 2000
360
US
Hello,

I'm looking for code to place in the Valid Event of a ComboBox in a Grid that would validate a users entry. When the criteria is not met, I want to cancel (or exit) the Valid Event, give the user a Messagebox with info on the problem, and then keep the focus on that same ComboBox so the user can correct their entry.

I was hoping for a brief description or explanation of the DODEFAULT() and the NODEFAULT() functions and how to apply them. I've read VFP 7's help and the Hacker's guide but still can't seem to grasp the basic concepts.

Any takers?

Dave

The 2nd mouse gets the cheese.
 
Hi

When you subclass a parent class to a new class.
WHEN you say DODEFAULT()
The parent class code of the same event is run

WHEN you say NODEFAULT
The parent class code is not done..

Example..

ParentForm
RightClick
WAIT WINDOW "Parent Class Code"


In the ChildForm
RightClick
WAIT WINDOW "I am Child Wait"
DODEFAULT() && this will display Parent class code also.

try now in child form..

RightClick
WAIT WINDOW "I am Child Wait"
NODEFAULT && no parent class action

:)

ramani :)
(Subramanian.G)
 
Hi Ramani,

No to sure on how to apply that to "canceling the valid event" and retaining focus on the combobox. Sorry, these functions are kind of new territory to me.

Dave

The 2nd mouse gets the cheese.
 
Dave,
In the first situation, just add something like the following to the Valid method:
Code:
IF NOT (validcode)
   Messagebox("Nope!")
   RETURN .F.
ENDIF
As far as DODEFAULT() goes, you use this to execute the default code of the parent class - normally you only need do this in a subclass. Otherwise the code in the subclass will happen instead of the parent class code - including none if you include a single blank or * in the method code!

It's important to note that NODEFAULT is a command - not a method. You'll get syntax errors in VFP 8+ if you include the ()'s. NODEFAULT will override the default behaviour of the VFP baseclass. e.g. In the lostfocus() of a control the default behaviour is to setfocus to the next control in the tab order. If you want to setfocus() somewhere else, then you need to include NODEFAULT, or your setfocus will happen and THEN VFP will setfocus where it wants to!

What NODEFAULT causes not to happen depends on the method and sometimes on the control type.

Rick
 

- Much appreciated Ramani -

Thanks,

Dave

The 2nd mouse gets the cheese.
 
Hi

Here is an example.. Copy and run as a PRG
*********************************
PUBLIC oform1
oform1=NEWOBJECT("form2")
oform1.Show
RETURN
*********************************
DEFINE CLASS form2 AS form1

PROCEDURE Command1.Click
=MESSAGEBOX("I am Child Command1 - Press any key to see Parent Click",16)
DODEFAULT()
ENDPROC

PROCEDURE Command2.Click
=MESSAGEBOX("I am Child Command2 - continue to see nothing more",16)
NODEFAULT
ENDPROC

ENDDEFINE
*****************************
DEFINE CLASS form1 AS form
Top = 0
Left = 0
Height = 400
Width = 400
DoCreate = .T.
Caption = "Form1"
Name = "Form1"

Add Object command1 As CommandButton With ;
AutoSize = .T., ;
Top = 12, ;
Left = 12, ;
Height = 27, ;
Caption = "Parent and Child Code", ;
Name = "Command1"

Add Object command2 As CommandButton With ;
AutoSize = .T., ;
Top = 48, ;
Left = 12, ;
Height = 27, ;
Caption = "Parent Code", ;
Name = "Command2"

PROCEDURE Command1.Click
=MESSAGEBOX("I am Parent Command1 ",16)
ENDPROC

PROCEDURE Command2.Click
=MESSAGEBOX("I am Parent Command2 ",16)
ENDPROC
ENDDEFINE
******************************
:)

ramani :)
(Subramanian.G)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top