Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
My first test with oo
Message
From
26/01/2004 20:02:06
 
 
To
22/01/2004 11:08:28
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00869519
Message ID:
00870841
Views:
9
>Hi,
>
>I have created my first form via oo. On this form i've put all my objects (cmdbuttons, textboxes,....)
>
>
>Now i want to put an event behind the click methode of one of my commandbuttons.
>
>And now i wonder how i will do that... restart and make first a class of my button and put the code behind. And then create it on my form.
>
>Or is there a way to put the code behind the click when i start from nothing, create and add the object on the form and then put the code behind the click ?
>
>Can somebody give me a quick boost ?
>
>Thnx

Hi Kurt,

Did you create your form with pure code in a .PRG or using the visual class designer?

Something that helps me when I am having a difficult time with OOP is to create a form class using the visual class designer and add buttons and textboxes and other controls. I then add code to the various control and form methods. After saving the form class, I open the class library using the Class Browser, click on the form class and then click on the View Class Code button (it's the one just to the left of the binoculars button) to take a look at how the form class looks as code.

When you are playing around with inheritance, you may want to create a button class based on the Fox native class, commandbutton. Add a few properties and methods and put code behind the methods. Then create a subclass of your new button class and change some of the property values and method code and save it. Then create subclasses of both of these classes, making some changes. Now, put them all on a form along with a SUSPEND command in the Load event of the form so you can use the debugger to step thru each line of code to see what happens when you click each button....be sure to put NODEFAULT and DODEFAULT() (note, NODEFAULT is a command and DODEFAULT() is a function) in various places in the button methods to see how these impact code execution.


Here are two button classes I use frequently...aButton and cButton. aButton is based on CommandButton and is an abstract class, meaning it never is directly instantiated but, rather, is used to define the new properties and methods that may be further enhanced by my concrete classes (cButton). In other words, aButton is never used on the form, cButton is used. Here are the objects as code:

aButton
**************************************************
*-- Class:        abutton (c:\dev\heat\classes\blender.vcx)
*-- ParentClass:  commandbutton
*-- BaseClass:    commandbutton
*-- Time Stamp:   01/18/04 09:12:02 PM
*
DEFINE CLASS abutton AS commandbutton


	Height = 27
	Width = 84
	Caption = "Command"
	Name = "abutton"

	*-- If TRUE, this control is enabled if thisform.lEditMode = .T.
	leditenabled = .F.

	*-- If TRUE and thisform has an lEditMode property, this control's .Enabled property is affected by its .lEditEnabled property.
	leditaware = .F.


	PROCEDURE Refresh
		  
		  if this.lEditAware
		    if type('thisform.lEditMode') <> 'U'
		      if this.lEditEnabled
		        this.enabled = thisform.lEditMode
		      else
		        this.enabled = not thisform.lEditMode
		      endif
		    endif
		  endif
		  
	ENDPROC


ENDDEFINE
*
*-- EndDefine: abutton
**************************************************
cButton
**************************************************
*-- Class:        cbutton (c:\dev\heat\classes\blender.vcx)
*-- ParentClass:  abutton (c:\dev\heat\classes\blender.vcx)
*-- BaseClass:    commandbutton
*-- Time Stamp:   01/08/04 09:07:00 PM
*
DEFINE CLASS cbutton AS abutton


	Name = "cbutton"


ENDDEFINE
*
*-- EndDefine: cbutton
**************************************************
If I wanted to add some code to the Refresh event in cButton that runs, in addition to the code in aButton.Refresh(), I'd need to use a combination of NODEFAULT and DODEFAULT() like so:
**************************************************
*-- Class:        cbutton (c:\dev\heat\classes\blender.vcx)
*-- ParentClass:  abutton (c:\dev\heat\classes\blender.vcx)
*-- BaseClass:    commandbutton
*-- Time Stamp:   01/08/04 09:07:00 PM
*
DEFINE CLASS cbutton AS abutton


	Name = "cbutton"

	PROCEDURE Refresh
		  
		  nodefault    && Prevents aButton.Refresh code from firing after this method
		  
		  if this.lEditAware
		    if type('thisform.lScanning') <> 'U'
		      if thisform.lScanning
		        this.enabled = .T.  && Disable this control during scanning
		      else
		        DoDefault()  && Perform normal enable check in parent class method
		      endif
		    endif
		  endif
		  
	ENDPROC

ENDDEFINE
*
*-- EndDefine: cbutton
**************************************************
Hope it helps to see code. :)

Jason
---------
Single field, surrogate primary keys....because it's sexier!

Third normal form is more than just a good idea.
Previous
Reply
Map
View

Click here to load this message in the networking platform