| xHarbour Reference Documentation > Statement Reference |
![]() |
![]() |
![]() |
Declares a message name for a method.
MESSAGE <MessageName> METHOD <MethodName> MESSAGE <MessageName> IN <SuperClass> MESSAGE <MessageName> IS <MethodName> IN <SuperClass> MESSAGE <MessageName> TO <ContainedObject> MESSAGE <MessageName> IS <MethodName> TO <ContainedObject>
The MESSAGE statement can only be used within the class declaration between CLASS and ENDCLASS. It declares a message that invokes a method of a different name in the declared class or its super class.
MESSAGE is used to resolve ambiguities when a class inherits from one or more super classes which have the same method names. The statement can also be used to invoke a method via an alternative name.
| See also: | ACCESS, ASSIGN, CLASS, DATA, DELEGATE, METHOD (declaration), VAR |
| Category: | Class declaration , Declaration , xHarbour extensions |
| Header: | hbclass.ch |
| Source: | vm\classes.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// In the example a Subclass uses the method implementation
// of a Super class but redefines the message to send to
// an object. Message :print() invokes method :show().
#include "Hbclass.ch"
PROCEDURE Main
LOCAL obj := TextFile():new( "Text.prg" )
obj:open()
obj:print()
obj:close()
RETURN
CLASS Text
EXPORTED:
DATA string
METHOD init(c) INLINE ( ::string := c, self )
METHOD show INLINE QOut( ::string )
ENDCLASS
CLASS TextFile FROM Text
EXPORTED:
DATA fileName
METHOD init
METHOD open
METHOD close
MESSAGE print IS show IN Text
ENDCLASS
METHOD init( cFile, cText ) CLASS TextFile
::fileName := cFile
IF Valtype( cText ) == "C"
::text:init( cText )
ELSE
::text:init( Memoread(::fileName ) )
ENDIF
RETURN self
METHOD open CLASS TextFile
SET ALTERNATE ON
SET ALTERNATE TO (::fileName)
RETURN
METHOD close CLASS TextFile
SET ALTERNATE TO
SET ALTERNATE OFF
RETURN
http://www.xHarbour.com