FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to override a method in Fivewin
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
How to override a method in Fivewin
Posted: Mon Oct 22, 2007 09:56 PM

To all,
How could you override a method in FW?
I would like to disable VK_LEFT and VK_RIGHT and to use this keys to navigate between the different tabs of a folder.
Thanks in advance,
Otto

METHOD KeyDown( nKey, nFlags ) CLASS TWBrowse

do case
case nKey == VK_UP
::GoUp()

  case nKey == VK_DOWN
       ::GoDown()

  case nKey == VK_LEFT
       ::GoLeft()

  case nKey == VK_RIGHT
       ::GoRight()

  case nKey == VK_HOME
       ::GoTop()

  case nKey == VK_END
       ::GoBottom()

  case nKey == VK_PRIOR
       if GetKeyState( VK_CONTROL )
          ::GoTop()
       else
          ::PageUp()
       endif

  case nKey == VK_NEXT
       if GetKeyState( VK_CONTROL )
          ::GoBottom()
       else
          ::PageDown()
       endif

  otherwise
       return Super:KeyDown( nKey, nFlags )

endcase

return 0

Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
How to override a method in Fivewin
Posted: Mon Oct 22, 2007 11:29 PM

Hi Otto,

If you are using xHarbour, you can use this, in your main prg:

OVERRIDE METHOD <Method> IN CLASS <Class> WITH <YourMethod>

In my case, I use this way:

OVERRIDE METHOD SayBitmap IN CLASS TREPORT WITH KSayBitMap

Hope this helps,

Best regards,

Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
How to override a method in Fivewin
Posted: Tue Oct 23, 2007 06:09 AM

Hello Kleyber,
thank you for your help. Do you think this should also work with harbour?
Regards,
Otto

Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
How to override a method in Fivewin
Posted: Tue Oct 23, 2007 10:28 PM

Hi Otto,

I really don't know, because I don't use Harbour... maybe Antonio can answer your question about the OVERRIDE command.

Best Regards,

Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to override a method in Fivewin
Posted: Wed Oct 24, 2007 06:18 AM

Otto,

Just try it. I have never used it and I don't recommend it, as thats not the way object oriented programming should be used

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
How to override a method in Fivewin
Posted: Wed Oct 24, 2007 07:05 PM

Antonio,

Can you tell me why you don't recommend this way? I use this instead of changing the original method and have to recreate the FIVEHX or recompile the prg with my project.

Best regards,

Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to override a method in Fivewin
Posted: Wed Oct 24, 2007 07:17 PM

Kleyber,

It may work fine, I agree, but the right way to modify a class is to inherit a new one from it, using object oriented programming

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
How to override a method in Fivewin
Posted: Wed Oct 24, 2007 07:23 PM

Antonio,

Now I understand. Thanks for clarifyng.

Best regards,

Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 682
Joined: Tue Feb 14, 2006 09:48 AM
How to override a method in Fivewin
Posted: Thu Oct 25, 2007 03:21 PM

I agree Antonio, but if you want to change for example a method from tGet.
If I inherit a new class from tGet and i want to use REDEFINE GET... , I must change the CH files too.
Any other easy way. Thanks in advance.

Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to override a method in Fivewin
Posted: Thu Oct 25, 2007 03:40 PM

Biel,

Yes, OVERRIDE METHOD is very usefull, but its "dangerous" for object oriented programming beginners :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
How to override a method in Fivewin
Posted: Fri Oct 26, 2007 03:35 PM

Kleyber

Saludos :-)

podrias traducirme por favor.

Sobre el topico, puedo decir que efectivamente la mejor y mas adecuada manera es la que indica Antonio Linares, pero es necesario modificar la definiciones de Comandos, y para usuario noveles como yo :-) es dificil.

Pero en algunos casos donde el cambio es minimos es posible la redifinicion o agregar nuevos metodos, sin mayores traumas.

yo personalmente tego un prg con los metodos modificados o agregados y sin necesidad de recompilar los fuentes de fwh.

pero por experiencia el algunos casos aislados podria presentar una dificultad.

hoy pondre un ejemplo de uso. :-)

salu2
carlos vargas

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
How to override a method in Fivewin
Posted: Fri Oct 26, 2007 04:06 PM
Hola Carlos,

Con gusto haré la trducción.

-- SET ENGLISH ON


About the subject, I can say that the best and adequate way to override a method is what Antonio said, but it's necessary to change all commands
definitions, and for a beginner like me it's difficult.

But in some cases, where the changes are minimal, it's possible to redefine or append new methods, without problems.

I personally have a prg with modified or appended methods and without need to recompile the fwh source codes.

But in my experience, in some isolated cases, this could present some difficulties.

Today I'll post an example about it.

Regards,

Carlos Vargas


Saludos,
Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
How to override a method in Fivewin
Posted: Fri Oct 26, 2007 09:47 PM
In my Main PRG
#include "fivewin.ch"

procedure main()
    ...
   OverrideAndExtend()
    ...
    define window ...
    ...
    activate window ...
return


in other .prg
/*-------------------------------------------------------------------------------------------------*/

PROCEDURE OverrideAndExtend()
   EXTEND CLASS TFOLDER  WITH METHOD RefreshPages
   EXTEND CLASS TFOLDER  WITH METHOD GoFirstControl
   EXTEND CLASS TDIALOG  WITH METHOD RefreshDialog
   RETURN

/*-------------------------------------------------------------------------------------------------*/
STATIC FUNCTION RefreshDialog( nPos )
   LOCAL SELF := HB_QSelf()
   DEFAULT nPos := 0
   AEval( ::aControls, { | oCtrl | oCtrl:Refresh() } )
   IF nPos > 0 .AND. Len( ::aControls ) > 0
      ::aControls[ nPos ]:SetFocus()
   ENDIF
   RETURN NIL

/*-------------------------------------------------------------------------------------------------*/

STATIC FUNCTION RefreshPages()
   LOCAL SELF := HB_QSelf()
   LOCAL oPage
   FOR EACH oPage IN ::aDialogs
      AEval( oPage:aControls, { | oCtrl | oCtrl:Refresh() } )
   NEXT
   RETURN NIL

/*-------------------------------------------------------------------------------------------------*/

STATIC FUNCTION GoFirstControl()
   LOCAL SELF := HB_QSelf()
   ::aDialogs[ 1 ]:aControls[ 1 ]:SetFocus()
   RETURN NIL

/*-------------------------------------------------------------------------------------------------*/
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
How to override a method in Fivewin
Posted: Fri Oct 26, 2007 10:28 PM
Aca un codigo inicial para hacer lo que pides, falta codificar un poco
lo referente al movimiento de las page del folder, en este ejemplo solamente pasa de la pagina 1 a la pagina 2.

otra cosa es que no he probado el codigo, pero en teoria deberia funcionar. :-), si no pues habria que hacerle pequeños ajustes, pero la idea esta plasmada :-)

#include "fivewin.ch"

PROCEDURE main()
  ...

  OverrideAndExtend()
  ...
  redefine folder oFolder ...
  ...
  redefine listbox oBrw ...

  oBrw:oFolder := oFolder
  ...

RETURN


/*---------------------------------------------------------------------------*/

#include "vkey.ch"

PROCEDURE OverrideAndExtend()
   
   /*new data and method*/
   EXTEND CLASS TWBROWSE WITH DATA   oFolder
   EXTEND CLASS TWBROWSE WITH METHOD NextPageOnFolder
   EXTEND CLASS TWBROWSE WITH METHOD PrevPageOnFolder

   /*change method*/
   OVERRIDE METHOD KeyDown CLASS TWBROWSE WITH METHOD MyKeyDown

   RETURN 

/*---------------------------------------------------------------------------*/

STATIC FUNCTION NextPageOnFolder()
   LOCAL SELF := HB_QSelf()
   LOCAL nCountPage := len( ::oFolder:aDialogs )

   //TODO: Make code correct :-)
 
   ::oFolder:SetOption(1)

   RETURN NIL

/*---------------------------------------------------------------------------*/

STATIC FUNCTION PrevPageOnFolder()
   LOCAL SELF := HB_QSelf()
   LOCAL nCountPage := len( ::oFolder:aDialogs )

   //TODO: Make code correct :-)

   ::oFolder:SetOption(2)

   RETURN NIL

/*---------------------------------------------------------------------------*/

STATIC FUNCTION MyKeyDown( nKey, nFlags )
    LOCAL SELF := HB_QSelf()
   
    DO CASE
    CASE nKey == VK_UP
        ::GoUp()
    CASE nKey == VK_DOWN
        ::GoDown()
    CASE nKey == VK_LEFT //modify
        IF ::oFolder=NIL
            ::GoLeft()
        ELSE
            ::PrevPageOnFolder()
        ENDIF        
    CASE nKey == VK_RIGHT //modify
        IF ::oFolder=NIL
            ::GoRight()
        ELSE
            ::NextPageOnFolder()
        ENDIF
    CASE nKey == VK_HOME
        ::GoTop()
    CASE nKey == VK_END
        ::GoBottom()
    CASE nKey == VK_PRIOR
        IF GetKeyState( VK_CONTROL )
            ::GoTop()
        ELSE
            ::PageUp()
        ENDIF

     CASE nKey == VK_NEXT
         IF GetKeyState( VK_CONTROL )
             ::GoBottom()
         ELSE
             ::PageDown()
         ENDIF

     OTHEWISE
         RETURN Super:KeyDown( nKey, nFlags )
     ENDCASE

RETURN 0

/*---------------------------------------------------------------------------*/


salu2
carlos vargas
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
How to override a method in Fivewin
Posted: Sat Oct 27, 2007 08:00 AM

Hello Carlos,
Thank you for your help. Could it be that EXTEND CLASS is only avaiable in xHarbour?
Syntax error: "syntax error at 'CLASS'"

I will try with inherit.
Thanks again,
Regards,
Otto