DynObj with modifable INLINEs and METHODs added
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
--- \source\tcpp\cvstest\harbour\source\rtl\classes.c Tue May 11 20:23:38 1999
|
||||
+++ \source\tcpp\harb21-2\source\rtl\classes.c Wed May 12 23:21:24 1999
|
||||
+++ \source\tcpp\harb21-2\source\rtl\classes.c Thu May 13 10:52:36 1999
|
||||
@@ -136,12 +136,22 @@
|
||||
|
||||
static HARBOUR GetData( void )
|
||||
@@ -25,10 +25,12 @@
|
||||
}
|
||||
|
||||
static HARBOUR GetClassData( void )
|
||||
@@ -505,4 +515,12 @@
|
||||
@@ -503,6 +513,59 @@
|
||||
else
|
||||
{ /* TODO: Crash code */
|
||||
}
|
||||
}
|
||||
|
||||
+}
|
||||
+
|
||||
+HARBOUR __WDATAINC() /* <nSeq> = __wDataInc( <hClass> )*/
|
||||
+{
|
||||
+ WORD wClass = _parnl( 1 );
|
||||
@@ -37,4 +39,49 @@
|
||||
+ _retni( ++pClasses[ wClass - 1 ].wDatas ); /* Return and increase */
|
||||
+} /* number of DATAs */
|
||||
+
|
||||
+HARBOUR CLASSMOD() /* Modify message (only for INLINE and METHOD) */
|
||||
+ /* <xOld> := ClassMod(<oObj>,<cSymbol>,<pFunction> */
|
||||
+{
|
||||
+ PITEM pString = _param( 2, IT_STRING );
|
||||
+ PSYMBOL pMessage = GetDynSym( pString->value.szText )->pSymbol;
|
||||
+ PDYNSYM pMsg = ( PDYNSYM ) pMessage->pDynSym;
|
||||
+ PCLASS pClass;
|
||||
+
|
||||
+ WORD wClass = _parni( 1 );
|
||||
+ WORD wAt;
|
||||
+ WORD wLimit;
|
||||
+
|
||||
+ HARBOURFUNC pFunc;
|
||||
+
|
||||
+ if( wClass && wClass <= wClasses )
|
||||
+ {
|
||||
+ pClass = &pClasses[ wClass - 1 ];
|
||||
+ wAt = ( ( ( unsigned ) pMsg ) % pClass->wHashKey ) * BUCKET;
|
||||
+ wLimit = wAt + BUCKET;
|
||||
+
|
||||
+ while( wAt < wLimit )
|
||||
+ {
|
||||
+ if( pClass->pMethods[ wAt ].pMessage == pMsg )
|
||||
+ { /* Requested method found */
|
||||
+ pFunc = pClass->pMethods[ wAt ].pFunction;
|
||||
+ if( pFunc == EvalInline ) /* INLINE method changed */
|
||||
+ {
|
||||
+ ArraySet( &pClass->aInlines, pClass->pMethods[ wAt ].wData,
|
||||
+ _param( 3, IT_BLOCK ) );
|
||||
+ }
|
||||
+ else if( ( pFunc == SetData ) || ( pFunc == GetData ) )
|
||||
+ /* Not allowed for DATA */
|
||||
+ {
|
||||
+ printf( "Cannot modify a DATA item\n");
|
||||
+ } /* TODO : Real error */
|
||||
+ else /* Modify METHOD */
|
||||
+ {
|
||||
+ pClass->pMethods[ wAt ].pFunction = ( HARBOURFUNC ) _parnl( 3 );
|
||||
+ }
|
||||
+ }
|
||||
+ wAt++;
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,12 +60,32 @@ function Main()
|
||||
ClassAdd( oForm:ClassH, "cHelp" , nSeq, MET_DATA )
|
||||
ClassAdd( oForm:ClassH, "_cHelp", nSeq, MET_DATA )
|
||||
|
||||
|
||||
oForm:cHelp := "This is a real tricky test"
|
||||
|
||||
QOut( "Data items after" )
|
||||
HBDebug( oForm )
|
||||
|
||||
QOut( "Let's attach a bigger smile" )
|
||||
|
||||
ClassMod( oForm:ClassH, "Smile", @BigSmile() )
|
||||
|
||||
QOut( "Let's smile" )
|
||||
oForm:Smile()
|
||||
|
||||
/* QOut( "Let's crash" )
|
||||
ClassMod( oForm:ClassH, "cText", 24 )
|
||||
ClassMod( oForm:ClassH, "_cText", 24 ) */
|
||||
|
||||
QOut( "And CalcArea() will now give a result in square inches" )
|
||||
|
||||
ClassAdd( oForm:ClassH, "CalcArea", ;
|
||||
{|self| ( ::nRight - ::nLeft ) * ( ::nBottom - ::nTop ) / (2.54*2.54) },;
|
||||
MET_INLINE )
|
||||
|
||||
QOut( "What is the Form area ?" )
|
||||
QOut( oForm:CalcArea() )
|
||||
|
||||
QOut( "Just one left : Delete" )
|
||||
return nil
|
||||
|
||||
|
||||
@@ -115,6 +135,14 @@ static function Smile()
|
||||
return self
|
||||
|
||||
|
||||
static function BigSmile()
|
||||
|
||||
local self := QSelf()
|
||||
|
||||
QOut( ":-)))" )
|
||||
return self
|
||||
|
||||
|
||||
function Pause()
|
||||
|
||||
__Accept( "Pause :" )
|
||||
|
||||
Reference in New Issue
Block a user