On Tue, 02 Jun 2009, Angel Pais wrote:
Hi,
> While you are at it...
> Would it be possible to implement this in Harbour ?
> <quote from docs>
> Class
> Abstract()
> Syntax
> :noMethod( cMessage, [<xValue>,...] ) --> xReturn
> Parameters
> <cMessage>
> The message send to the object.
> <xValue>
> The parameters passed by the callee to the undefined method.
> Return
> The return value will be interpreted as the return value of the called
> undefined method.
> Description
> If an undefined method is called, a runtime error is raised. However, when
> :noMethod() is declared in the class, the runtime error will not occur.
> Instead, program execution is directed to this method. The parameter
> <cMessage> contains the name of the undefined method, followed by the
> parameters the callee has passed to the method call.
We already have such functionality though with different syntax.
We can declare ERROR HANDLER method which is executed in such case
and can be used for dynamic messages.
Just look at this example of HashObject() which Mindaugas sent few hours
ago to this list:
On Wed, 03 Jun 2009, Mindaugas Kavaliauskas wrote:
> #include "hbclass.ch"
> PROC MAIN()
> LOCAL hValue := HashObject()
> hValue:VAR1 := 123.45
> hValue:VAR2 := DATE()
> ? hValue:VAR1, hValue:VAR2
> RETURN
>
> CREATE CLASS HashObject
> VAR __hash INIT {=>}
> ERROR HANDLER OnError()
> ENDCLASS
>
> METHOD OnError( xValue ) CLASS HashObject
> LOCAL cMessage := __GETMESSAGE()
> IF PCOUNT() == 1 .AND. LEFT( cMessage, 1 ) == "_"
> RETURN QSELF():__hash[ SUBSTR( cMessage, 2 ) ] := xValue
> ENDIF
> RETURN QSELF():__hash[ cMessage ]
It creates Hash array encapsulated in HashObject which can be used
to access/assign hash using OOP interface.
BTW It's really nice idea and I will want to add such class to Harbour RTL.
> There is also a :NoIvar for undefined instance variables on objects
> It is very usefull to build "virtual dynamic methods and variables on
> classes". I'm using those ones on xbase++
In Harbour just like in Clipper there is not difference between methods
and instance variables. Both are accessed by the same messages and only
for assign operation the message name is prefixed with "_" so it's not
necessary. The above example created by Mindaugas nicely illustrates it.
best regards,
Przemek
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour