Page 1 of 1

OVERRIDE

PostPosted: Mon Nov 13, 2023 11:19 am
by Silvio.Falconi
I saw that I can modify a method of a class directly with the OVERRIDE command without having to modify the class.
Can I add Data or new methods with the same technique? and how ?

Re: OVERRIDE

PostPosted: Mon Nov 13, 2023 11:25 am
by Antonio Linares

Re: OVERRIDE

PostPosted: Mon Nov 13, 2023 11:49 am
by Silvio.Falconi
Antonio Linares wrote:Dear Silvio,

Please review this:
https://github.com/harbour/core/blob/master/src/rtl/objfunc.prg



for modify a Method run ok with

Code: Select all  Expand view
#xcommand OVERRIDE METHOD <!Message!> [IN] CLASS <!Class!> ;
                             WITH [METHOD] <!Method!> [SCOPE <Scope>] => ;
            __clsModMsg( <Class>():classH, #<Message>, @<Method>() )


sample:

Code: Select all  Expand view
OVERRIDE METHOD BuildButtonBar IN CLASS TPreview WITH PreviewBuildButtonBar


I not found the #command to add data or add methods

EXTEND CLASS TPreview WITH DATA aDefaultCols not run

Re: OVERRIDE

PostPosted: Mon Nov 13, 2023 11:52 am
by Antonio Linares
FUNCTION __objAddData( oObject, cSymbol )

it is inside:
https://github.com/harbour/core/blob/master/src/rtl/objfunc.prg

Re: OVERRIDE

PostPosted: Mon Nov 13, 2023 12:02 pm
by Silvio.Falconi
Antonio Linares wrote:FUNCTION __objAddData( oObject, cSymbol )

it is inside:
https://github.com/harbour/core/blob/master/src/rtl/objfunc.prg


I tried with

#xcommand EXTEND DATA <!Message!> [IN] CLASS <!Class!>
__objAddData( <Class>():classH, #<Message> )

EXTEND DATA aDefaultCols IN CLASS TPreview

not run

make error on compilation

ut_over_Bro.prg(8) Error E0007 Missing => in #translate/#command
ut_over_Bro.prg(9) Error E0030 Syntax error "syntax error at '<'"
ut_over_Bro.prg(12) Error E0030 Syntax error "syntax error at 'DATA'"
ut_over_Bro.prg(13) Error E0030 Syntax error "syntax error at 'DATA'"

Re: OVERRIDE

PostPosted: Mon Nov 13, 2023 12:12 pm
by Silvio.Falconi
#xcommand EXTEND DATA <!Message!> [IN] CLASS <!Class!> => ;
__objAddData( <Class>():classH, #<Message> )

seem run ok then

if I add a data sample :

EXTEND DATA aDefaultCols IN CLASS TXBrowse

give me an error

Error occurred at: 11/13/23, 13:13:45
Error description: Error BASE/3101 Argument error: __OBJADDDATA

Stack Calls
===========
Called from: => __ERRRT_BASE( 0 )
Called from: ../../../objfunc.prg => __OBJADDDATA( 0 )
Called from: ut_over_Bro.prg => UT_OVERRIDE( 12 )

Re: OVERRIDE

PostPosted: Mon Nov 13, 2023 4:04 pm
by Antonio Linares
Dear Silvio,

You add a new DATA to the object, not to the class:

#xcommand EXTEND DATA <!Message!> [IN] OBJECT <!object!> => ;
__objAddData( <object>, #<Message> )

Re: OVERRIDE

PostPosted: Tue Nov 14, 2023 8:52 am
by Silvio.Falconi
Antonio Linares wrote:Dear Silvio,

You add a new DATA to the object, not to the class:

#xcommand EXTEND DATA <!Message!> [IN] OBJECT <!object!> => ;
__objAddData( <object>, #<Message> )


which is the object ?

sample
If I must add a data into Txbrowse how I can make ?


EXTEND DATA aDefaultCols IN OBJECT TXBrowse

give me not found txbrowse

Re: OVERRIDE

PostPosted: Tue Nov 14, 2023 2:03 pm
by Antonio Linares
Dear Silvio,

This example works fine:
Code: Select all  Expand view
function Main()

   local oError := ErrorNew()
   
   __objAddData( oError, "test" )
   
   oError:test = "hello"
   ? oError:test

return nil