Difference between revisions of "CLASS - Methods"

From Recital Documentation Wiki
Jump to: navigation, search
 
(3 intermediate revisions by one user not shown)
Line 10: Line 10:
  
 
==See Also==
 
==See Also==
[[ADDPROPERTY()]], [[CLASS]], [[CLASS - Parameters]], [[CLASS - Properties]], [[CLASS - Scoping]], [[CREATEOBJECT()]], [[DEFINE CLASS]], [[DODEFAULT()]],[[METHOD]], [[NEWOBJECT()]], [[REMOVEPROPERTY()]]
+
[[ACLASS()]], [[ADDPROPERTY()]], [[AMEMBERS()]], [[CLASS]], [[CLASS - Parameters]], [[CLASS - Properties]], [[CLASS - Scoping]], [[COMPOBJ()]], [[CREATEOBJECT()]], [[DEFINE CLASS]], [[DISPLAY CLASSES]], [[DODEFAULT()]], [[FOREACH]], [[LIST CLASSES]], [[LOADOBJECT()]], [[METHOD]], [[NEWOBJECT()]], [[OBJECT()]], [[PRINT_HTML()]], [[PRINT_JSON()]], [[PRINT_R()]], [[PRINT_XML()]], [[REMOVEPROPERTY()]], [[REQUIRE_ONCE()]], [[SAVEOBJECT()]], [[SQL SELECT]], [[WITH]]
  
  
Line 47: Line 47:
  
 
Similarly, after a new value is assigned to a property, checks are made for ''<property>_assign'' and ''this_assign''.
 
Similarly, after a new value is assigned to a property, checks are made for ''<property>_assign'' and ''this_assign''.
 
  
 
====EXTERNAL====
 
====EXTERNAL====

Latest revision as of 11:34, 13 January 2010

Purpose

Define a method in a user-defined class


Syntax

METHOD <method name> [EXTERNAL]

RETURN


See Also

ACLASS(), ADDPROPERTY(), AMEMBERS(), CLASS, CLASS - Parameters, CLASS - Properties, CLASS - Scoping, COMPOBJ(), CREATEOBJECT(), DEFINE CLASS, DISPLAY CLASSES, DODEFAULT(), FOREACH, LIST CLASSES, LOADOBJECT(), METHOD, NEWOBJECT(), OBJECT(), PRINT_HTML(), PRINT_JSON(), PRINT_R(), PRINT_XML(), REMOVEPROPERTY(), REQUIRE_ONCE(), SAVEOBJECT(), SQL SELECT, WITH


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:


Name Description
init Called after an object is first created. This is a known as the constructor method and may also be named constructor.
destroy Called just prior to an object being destroyed. This is known as the destructor method and may also be named destructor.
<property>_access Property access notification for the property <property>.
<property>_assign Property assignment notification for the property <property>.
this_access Property access notification. This will be called for any property which does not have its own <property>_access method. May also be named getproperty.
this_assign Property assignment notification. This will be called for any property which does not have its own <property>_assign method. May also be named setproperty.
error Class specific error handler.


When a new object is created, and the class contains a method called init, that method is called to complete the process of creating the object. You can pass parameters to the init constructor method when you create the new object. The PARAMETERS statement must be specified in the method for accepting parameters. When the object is released, and it contains a method called destroy, that method is called prior to the object storage being released.

When a property is accessed and before its value is returned, a check is made to see if a method named <property>_access exists, where <property> is the name of the property. If this method exists, it is called. If not, a check is made to see if there is a method named this_access and it is called if it exists.

Similarly, after a new value is assigned to a property, checks are made for <property>_assign and this_assign.

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.

PROCEDURE...ENDPROC

The PROCEDURE...ENDPROC syntax may also be used to define a method.


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 constructor and destructor
 
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 Server, Recital