Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Ilya Rabyy
  Where is Ilya Rabyy?
 Fountain Valley
 California - United States
 Ilya Rabyy
 Tags
Subject: RE: Egg or bird: what's first?
Thread ID: 143433 Message ID: 143458 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: Classes and Objects
Date: Tuesday, August 28, 2007 11:31:35 PM         
   


> Colleagues,
>
> everybody knows (I hope) that, taking the Q. in subject literally, egg (fish, amphybians, then reptiles) was first and bird (dinosaurs) appeared only afterwards. (Just to lighten up the mood :).
>
> Now, when you instantiated some class, and you have some code for some event in that object, and the base class has different code for that same event - which code is being executed first (bar NODEFAULT/DODEFAULT())?
>
> For instance: you have a class MyCommButton, and some (quasi-)generic code in its Click event procedure; you instantiate this class - drag/drop into some form, - name it cmdWhatever, and add your specific code into that same Click event procedure. You run your program, bring up this form on display, click on that cmdWhatever...
>
> What code is being executed first: generic (in the class) or specific (added by you)?
>
> TIA!
>
> Regards,
>
> Ilya

Your code executes first, no user code from subclassed executes (overridden), then baseclass' code if it is a built-in event code or only your code if it's not built-in.

Consider this code:

define class myTextBox2 as myTextBox
 Procedure KeyPress && this one overrides the "user code" in base BUT not built-in code
 lparameters nKeyCode, nShiftAltCtrl
  if nKeyCode = asc("B")
    keyboard "A"

* Since built-in code would execute anyway BA would be written when you press B

* Prevent built-in code
*NODEFAULT

  endif
endproc

Procedure UserMethod && code written here overrides the code in base
  this.lSomething = .t. 
  dodefault() && as if you pasted parent class code here - need dodefault for it to execute
  this.lSomething = .f.
  dodefault() && as if you pasted parent class code here
enproc

enddefine

define class myTextBox as TextBox
lSomething = .f.

Procedure KeyPress
lparameters nKeyCode, nShiftAltCtrl
 if nKeyCode = asc("A")
   keyboard "B"
 endif
endproc

Procedure UserMethod
* Consider some long code here
if this.lSomething
  wait window "Yes sir"
else
  wait window "No sir"
endif
enproc
enddefine


PS: Even a space in edited code is considered as an override. If the method has parameters than make dodefault() call with parameters. You can use, now forgotten :: scope resolution operator to execute code from a higher level in class hierarchy and/or from another method - dodefault() is identical to parentclass::thismethod()

Cetin Basoz

ENTIRE THREAD

Egg or bird: what's first? Posted by Ilya Rabyy @ 8/28/2007 7:50:35 PM
RE: Egg or bird: what's first? Posted by Ken Murphy @ 8/28/2007 8:22:20 PM
RE: Egg or bird: what's first? Posted by Ilya Rabyy @ 8/28/2007 8:32:37 PM
RE: Egg or bird: what's first? Posted by Ken Murphy @ 8/28/2007 8:36:23 PM
RE: Egg or bird: what's first? Posted by Borislav Borissov @ 8/28/2007 11:42:40 PM
RE: Egg or bird: what's first? Posted by Cetin Basoz @ 8/28/2007 11:46:26 PM
RE: Egg or bird: what's first? Posted by Ken Murphy @ 8/28/2007 11:56:24 PM
RE: Egg or bird: what's first? Posted by Borislav Borissov @ 8/28/2007 11:56:41 PM
RE: Egg or bird: what's first? Posted by Ken Murphy @ 8/29/2007 12:03:44 AM
RE: Egg or bird: what's first? Posted by Cetin Basoz @ 8/29/2007 12:07:00 AM
RE: Egg or bird: what's first? Posted by Cetin Basoz @ 8/28/2007 11:31:35 PM