How to override a method in Fivewin

How to override a method in Fivewin

Postby Otto » Mon Oct 22, 2007 9: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
User avatar
Otto
 
Posts: 6132
Joined: Fri Oct 07, 2005 7:07 pm

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

Postby Otto » Tue Oct 23, 2007 6:09 am

Hello Kleyber,
thank you for your help. Do you think this should also work with harbour?
Regards,
Otto
User avatar
Otto
 
Posts: 6132
Joined: Fri Oct 07, 2005 7:07 pm

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

Postby Antonio Linares » Wed Oct 24, 2007 6: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Wed Oct 24, 2007 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Kleyber » Wed Oct 24, 2007 7:23 pm

Antonio,

Now I understand. Thanks for clarifyng.

Best regards,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Postby Biel EA6DD » Thu Oct 25, 2007 3: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/
User avatar
Biel EA6DD
 
Posts: 682
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca

Postby Antonio Linares » Thu Oct 25, 2007 3:40 pm

Biel,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby carlos vargas » Fri Oct 26, 2007 3: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)
User avatar
carlos vargas
 
Posts: 1704
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

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

Postby carlos vargas » Fri Oct 26, 2007 9:47 pm

In my Main PRG
Code: Select all  Expand view
#include "fivewin.ch"

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


in other .prg
Code: Select all  Expand view
/*-------------------------------------------------------------------------------------------------*/

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: 1704
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Postby carlos vargas » 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 :-)

Code: Select all  Expand view

#include "fivewin.ch"

PROCEDURE main()
  ...

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

  oBrw:oFolder := oFolder
  ...

RETURN



Code: Select all  Expand view

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

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

Postby Otto » Sat Oct 27, 2007 8: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
User avatar
Otto
 
Posts: 6132
Joined: Fri Oct 07, 2005 7:07 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Enrico Maria Giordano, Google [Bot] and 116 guests