Difference between revisions of "CLASS - Methods"
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
Line 84: | Line 84: | ||
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:Commands]] | [[Category:Commands]] | ||
+ | [[Category:Objects]] | ||
+ | [[Category:Objects Commands]] |
Revision as of 09:47, 2 June 2009
Contents
Class
Objects
Purpose
Define a method in a user-defined class
Syntax
METHOD <method name> [EXTERNAL]
RETURN
See Also
ADDPROPERTY(), CLASS, CLASS - Parameters, CLASS - Properties, CLASS - Scoping, CREATEOBJECT(), DEFINE CLASS, DODEFAULT(),METHOD, NEWOBJECT(), REMOVEPROPERTY()
Description
An object encapsulates properties and all of the methods that perform operations on the object. Encapsulation hides data within an object, and makes an object into a full self-contained operational unit. A class method is a self-contained function defined in the class, accessible only through an instantiation of the class.
You define the methods of a class using the METHOD command in the CLASS...ENDCLASS construct. The 'This.' operator is used to reference properties of the active object from within its methods. Parameters can be passed to a method, the PARAMETER statement can be used to define the parameters in the method.
<method name>
The <method name> must be unique name of up to 32 characters. The method is called using the "object.method()" syntax. You can create special methods in the class. When a new object is created, and the class contains a method called CONSTRUCTOR, that method is called to complete the process of creating the object. You can pass parameters to the CONSTRUCTOR method when you create the new object. The PARAMETER statement must be specified in the method for accepting parameters. When the object is released, and it contains a method called DESTRUCTOR, that method is called prior to the object storage being released. The Visual FoxPro equivalents are also supported: INIT for CONSTRUCTOR and DESTROY for DESTRUCTOR. When a property that has been defined with the NOTIFY clause is read, and the class contains a method called GETPROPERTY, that method is called. The property name is passed as an upper case character string to the GETPROPERTY method as a parameter. When a property that has been defined with the NOTIFY clause is updated, and the class contains a method called SETPROPERTY, that method is called. The property name, in upper case, and the new value are passed to the SETPROPERTY method as parameters.
EXTERNAL
Methods can be defined outside the CLASS...ENDCLASS construct with the METHOD command. The EXTERNAL clause is used to make an external method known to the CLASS...ENDCLASS construct. When a method is defined externally, its name should be preceded by the keyword METHOD, followed by the Class name, followed by two colon characters (e.g. Method MyClass::ExtMethod).
RETURN
The RETURN clause is used to specify the end of the method definition.
Example
// Example of External Method class Box method DrawFrame external endclass Method Box::DrawFrame parameters nX1, nY1, nX2, nY2, cFGCOL, cBGCOL @nX1,nY1 clear to nX2,nY2 @nX1,nY1 fill to nX2,nY2 ; color &(cFGCOL + "/" + cBGCOL) @nX1,nY1 to nX2,nY2 ; color &(cFGCOL + "/" + cBGCOL) return && DrawFrame oDIALOGOK = new Box() oDIALOGOK.DrawFrame(5,25,12,54, "R", "Gr") // Example of Visual FoxPro Method names class Box procedure Draw messagebox("This is the parent Draw Method") endproc && Draw endclass class Dialog1 of Box procedure Init messagebox("This is the object Init Method") endproc procedure Destroy messagebox("This is the object Destroy Method") endproc procedure Draw messagebox("This is the object Draw Method") dodefault() endproc && Draw endclass oDIALOG = createobject("Dialog1") oDIALOG.Draw() oDIALOG.AddProperty("myprop", "hello world") messagebox(oDIALOG.myprop) release oDIALOG
Products
Recital Database Server, Recital Mirage Server, Recital Terminal Developer