Page 1 of 1

Error al sobrecargar un metodo de una clase. (Solucionado)

PostPosted: Fri Nov 01, 2019 11:55 am
by jvtecheto
Hola amigos:

No he sobrecargado nunca una funcion de una clase, pero buscando en el foro encontre que se hace asi.

Code: Select all  Expand view

#include "FiveWin.ch"

OVERRIDE METHOD SaveState IN CLASS TWindow WITH XSaveState


FUNCTION XSaveState()
   
   if !Empty( ::hWnd ) .and. !::IsKindOf( "TCONTROL" ) //.and. !::WinStyle( WS_CHILD )
      return STRTOHEX( GetWindowPlacement( ::hWnd ) )
   endif

return ::Super:SaveState()

OVERRIDE METHOD RestoreState CLASS TWindow WITH XRestoreState

FUNCTION XRestoreState( cState )

   if !Empty( ::hWnd ) .and. !Empty( cState ) .and. !::IsKindOf( "TCONTROL" ) //.and. !::WinStyle( WS_CHILD )
      SetWindowPlacement( ::hWnd, HEXTOSTR( cState ) )
   endif

return ::Super:RestoreState(cState)
 


Este codigo es a indicacion de Mr. Rao que tengo que modificar un metodo de la clase TWindow, pero no me gusta tocar las clases originales de Fivewin.

el error al compilar es este.

c:\obraw\source\MODCLASS.prg(3) Error E0030 Syntax error "syntax error at 'METHOD'"

c:\obraw\source\MODCLASS.prg(8) Warning W0002 Ambiguous reference, assuming memvar 'SELF'

c:\obraw\source\MODCLASS.prg(8) Warning W0002 Ambiguous reference, assuming memvar 'SELF'

c:\obraw\source\MODCLASS.prg(9) Warning W0002 Ambiguous reference, assuming memvar 'SELF'

c:\obraw\source\MODCLASS.prg(12) Warning W0002 Ambiguous reference, assuming memvar 'SELF'

c:\obraw\source\MODCLASS.prg(14) Error E0030 Syntax error "syntax error at 'METHOD'"

c:\obraw\source\MODCLASS.prg(18) Warning W0002 Ambiguous reference, assuming memvar 'SELF'

c:\obraw\source\MODCLASS.prg(18) Warning W0002 Ambiguous reference, assuming memvar 'SELF'

c:\obraw\source\MODCLASS.prg(19) Warning W0002 Ambiguous reference, assuming memvar 'SELF'

c:\obraw\source\MODCLASS.prg(22) Warning W0002 Ambiguous reference, assuming memvar 'SELF'



Que estoy haciendo mal.

Gracias por vuestra ayuda inestimable.

Jose.

Re: Error al sobrecargar un metodo de una clase.

PostPosted: Fri Nov 01, 2019 12:46 pm
by cnavarro
Jose Vicente, por un lado has de definir en las funciones que utilizan ( Self, o lo que es lo mismo :: )
Code: Select all  Expand view

   Local Self := HB_QSelf()
 

y por otro, intenta definir los OVERRIDE dentro de una function, por ejemplo de la function Main, y prueba, no los pongas en lineas independientes de una function

Re: Error al sobrecargar un metodo de una clase.

PostPosted: Fri Nov 01, 2019 3:51 pm
by jvtecheto
Hola Cristobal .

Muchas gracias por la ayuda .

Defino una funcion asi

Code: Select all  Expand view

FUNCTION Mis_Clases()

OVERRIDE METHOD SaveState IN CLASS TWindow WITH XSaveState
OVERRIDE METHOD RestoreState IN CLASS TWindow WITH XRestoreState

RETURN NIL

FUNCTION XSaveState()

   Local Self:= HB_QSelf()
   
   if !Empty( Self:hWnd ) .and. !Self:IsKindOf( "TCONTROL" ) //.and. !SelfWinStyle( WS_CHILD )
      return STRTOHEX( GetWindowPlacement( Self:hWnd ) )
   endif

return Self:Super:SaveState()

FUNCTION XRestoreState( cState )

   Local Self:= HB_QSelf()

   if !Empty( Self:hWnd ) .and. !Empty( cState ) .and. !Self:IsKindOf( "TCONTROL" ) //.and. !SelfWinStyle( WS_CHILD )
      SetWindowPlacement( Self:hWnd, HEXTOSTR( cState ) )
   endif

return Self:Super:RestoreState(cState)

 


Y la llamo desde la funcion Main()

Code: Select all  Expand view

MisClases()
 


Me sigue dando error en la linea
Code: Select all  Expand view

OVERRIDE METHOD SaveState IN CLASS TWindow WITH XSaveState
 


error de sintaxis en METHOD ,

Creo que deberia tener un include de este archivo.
Code: Select all  Expand view

#include "\harbour\contrib\xhb\xhbcls.ch"
 


Yo no tengo la carpeta contrib\xhb y tampoco el fichero .ch

Alguien que haya sobrecargado algun metodo de una clase me puede informar como lo ha hecho el.

Muchisimas gracias.

Jose.

Re: Error al sobrecargar un metodo de una clase.

PostPosted: Fri Nov 01, 2019 3:59 pm
by cnavarro
jvtecheto wrote:Hola Cristobal .

Code: Select all  Expand view

OVERRIDE METHOD SaveState CLASS TWindow WITH XSaveState
 


Y me dice error de sintaxis en METHOD ,
Jose.


Prueba asi a ver si te funciona

Code: Select all  Expand view

OVERRIDE METHOD SaveState IN CLASS TWindow WITH XSaveState
 

Re: Error al sobrecargar un metodo de una clase.

PostPosted: Fri Nov 01, 2019 4:19 pm
by jvtecheto
Hola Cristobal:

Perdona pero lee el mensaje anterior (Lo he modificado) , con todo esto que te explico sigue dandome el error , creo que me falta el fichero .ch que informo en el correo.

este.

Code: Select all  Expand view

#include "\harbour\contrib\xhb\xhbcls.ch"
 


Como te digo yo no lo tengo en mi version de Harbour (La que provee Fivetech).

Sigo buscando , muchas gracias.

Saludos.

Jose.

Re: Error al sobrecargar un metodo de una clase.

PostPosted: Fri Nov 01, 2019 4:50 pm
by EBM
Hola José,

Te paso el contenido del archivo xhbcls.ch:



#ifndef XHB_CLS__CH_
#define XHB_CLS__CH_

#ifdef __HARBOUR__

#ifndef __XHARBOUR__

#include "hboo.ch"

#xtranslate __xhb_cls_scope( <scope>, .T. ) => <scope> + HB_OO_CLSTP_PERSIST
#xtranslate __xhb_cls_scope( <scope>, .F. ) => <scope>
#xtranslate __xhb_cls_scope( , .T. ) => HB_OO_CLSTP_PERSIST
#xtranslate __xhb_cls_scope( , .F. ) =>

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


#xcommand EXTEND CLASS <!Class!> WITH <data: DATA, VAR> <!VarName!> ;
[SCOPE <scope>] [<persist: PERSISTENT>] ;
[<case: NOUPPER>] => ;
__clsAddMsg( <Class>():classH, #<VarName>, ;
__cls_IncData( <Class>():classH ), ;
HB_OO_MSG_PROPERTY, NIL, ;
__xhb_cls_scope( <scope>, <.persist.> ) )

#xcommand EXTEND CLASS <!Class!> WITH METHOD <!Method!> [SCOPE <scope>] ;
[<persist: PERSISTENT>] [<case: NOUPPER>] => ;
__clsAddMsg( <Class>():classH, #<Method>, @<Method>(), ;
HB_OO_MSG_METHOD, NIL, ;
__xhb_cls_scope( <scope>, <.persist.> ) )


#xcommand EXTEND CLASS <!Class!> WITH MESSAGE <!Message!> METHOD <!Method!> ;
[SCOPE <scope>] [<persist: PERSISTENT>] ;
[<case: NOUPPER>] => ;
__clsAddMsg( <Class>():classH, #<Message>, @<Method>(), ;
HB_OO_MSG_METHOD, NIL, ;
__xhb_cls_scope( <scope>, <.persist.> ) )

#xcommand EXTEND CLASS <!Class!> WITH MESSAGE <!Message!> INLINE <code,...> ;
[SCOPE <scope>] [<persist: PERSISTENT>] ;
[<case: NOUPPER>] => ;
__clsAddMsg( <Class>():classH, #<Message>, ;
{| Self | HB_SYMBOL_UNUSED( Self ), <code> }, ;
HB_OO_MSG_INLINE, NIL, ;
__xhb_cls_scope( <scope>, <.persist.> ) )

#xcommand EXTEND CLASS <!Class!> WITH MESSAGE <Message>( <params,...> ) ;
INLINE <code,...> ;
[SCOPE <scope>] [<persist: PERSISTENT>] ;
[<case: NOUPPER>] => ;
__clsAddMsg( <Class>():classH, #<Message>, ;
{| Self, <params> | HB_SYMBOL_UNUSED( Self ), <code> }, ;
HB_OO_MSG_INLINE, NIL, ;
__xhb_cls_scope( <scope>, <.persist.> ) )

#endif /* __XHARBOUR__ */


#endif /* __HARBOUR__ */

#endif /* XHB_CLS__CH_ */



Espero te ayude

Saludos!

Eduardo Borondón Muñiz

Re: Error al sobrecargar un metodo de una clase.

PostPosted: Fri Nov 01, 2019 5:37 pm
by jvtecheto
Muchas gracias Eduardo

Ahora compila sin error.

Enviado desde mi POCOPHONE F1 mediante Tapatalk