Test added for dynamic DATA add

This commit is contained in:
Eddie Runia
1999-05-12 21:48:54 +00:00
parent 059c75babf
commit 547dcd5b03
2 changed files with 51 additions and 10 deletions

View File

@@ -0,0 +1,27 @@
--- \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 22:40:40 1999
@@ -136,12 +136,22 @@
static HARBOUR GetData( void )
{
- ArrayGet( stack.pBase + 1, pMethod->wData, &stack.Return );
+ PITEM pObject = stack.pBase + 1;
+ WORD wIndex = pMethod->wData;
+
+ if( wIndex > ArrayLen ( pObject ) ) /* Resize needed */
+ ArraySize( pObject, wIndex ); /* Make large enough */
+ ArrayGet( pObject, wIndex, &stack.Return );
}
static HARBOUR SetData( void )
{
- ArraySet( stack.pBase + 1, pMethod->wData, stack.pBase + 2 );
+ PITEM pObject = stack.pBase + 1;
+ WORD wIndex = pMethod->wData;
+
+ if( wIndex > ArrayLen( pObject ) ) /* Resize needed */
+ ArraySize( pObject, wIndex ); /* Make large enough */
+ ArraySet( pObject, wIndex, stack.pBase + 2 );
}
static HARBOUR GetClassData( void )

View File

@@ -20,33 +20,46 @@ function Main()
local oForm := TForm():New()
QOut( "What methods are in the class :")
HBDebug( aoMethod(oForm) )
QOut( "What methods are in the class :" )
HBDebug( aoMethod( oForm ) )
/* Let's add an inline at run-time. Should already be possible */
QOut( "Let's add inline 'CalcArea' at run-time to an already instanced class" )
ClassAdd( oForm:ClassH, "CalcArea", ;
{|self| (::nRight - ::nLeft) * (::nBottom - ::nTop) }, MET_INLINE )
{|self| ( ::nRight - ::nLeft ) * ( ::nBottom - ::nTop ) }, MET_INLINE )
QOut( "What methods are in the class :")
QOut( "What methods are in the class :" )
HBDebug( aoMethod( oForm ) )
QOut( "What is the Form area ?")
QOut( "What is the Form area ?" )
QOut( oForm:CalcArea() )
QOut( "Let's add method 'Smile' at run-time to an already instanced class" )
ClassAdd( oForm:ClassH, "Smile", @Smile(), MET_METHOD )
QOut( "What methods are in the class :")
QOut( "What methods are in the class :" )
HBDebug( aoMethod( oForm ) )
QOut( "Smile please " )
oForm:Smile()
/* The next code can _not_ be used in the offical classes.c */
QOut( "Let's add an additional data item" )
ClassAdd( oForm:ClassH, "cHelp" , 6, MET_DATA ) // 6th item !
ClassAdd( oForm:ClassH, "_cHelp", 6, MET_DATA )
HBDebug( aoData( oForm ) )
oForm:cHelp := "This is a real tricky test"
HBDebug( oForm )
return nil
function TForm()
static oClass
@@ -68,14 +81,15 @@ function TForm()
return oClass:Instance() // builds an object of this class
static function New()
local Self := QSelf()
::nTop = 10
::nLeft = 10
::nBottom = 20
::nRight = 40
::nTop := 10
::nLeft := 10
::nBottom := 20
::nRight := 40
return Self