How to override a method in Fivewin

User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

How to override a method in Fivewin

Post by Otto »

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
User avatar
Kleyber
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Post by Kleyber »

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
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Hello Kleyber,
thank you for your help. Do you think this should also work with harbour?
Regards,
Otto
User avatar
Kleyber
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Post by Kleyber »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
User avatar
Kleyber
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Post by Kleyber »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
User avatar
Kleyber
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Post by Kleyber »

Antonio,

Now I understand. Thanks for clarifyng.

Best regards,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Biel EA6DD
Posts: 680
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca
Contact:

Post by Biel EA6DD »

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/
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Biel,

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

Antonio Linares
www.fivetechsoft.com
User avatar
carlos vargas
Posts: 1421
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Post by carlos vargas »

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 _ 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 _ aislados podria presentar una dificultad.

hoy pondre un ejemplo de uso. :-)

salu2
carlos vargas
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
Kleyber
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Post by Kleyber »

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
User avatar
carlos vargas
Posts: 1421
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Post by carlos vargas »

In my Main PRG

Code: Select all

#include "fivewin.ch"

procedure main()
    ...
   OverrideAndExtend()
    ...
    define window ...
    ...
    activate window ...
return
in other .prg

Code: Select all

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

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)
User avatar
carlos vargas
Posts: 1421
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Post by carlos vargas »

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 :-)

Code: Select all


#include "fivewin.ch"

PROCEDURE main()
  ...

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

  oBrw:oFolder := oFolder
  ...

RETURN

Code: Select all


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

#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)
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

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
Post Reply