FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TXBrwColumn : changing and restoring a method
Posts: 55
Joined: Fri Jul 08, 2011 06:43 AM
TXBrwColumn : changing and restoring a method
Posted: Fri Aug 12, 2011 08:17 AM

Hello,

I know how to change a method (in xharbour) , but how can it be restored in it's original method ?

I tryed something with TXBrows( {|| TXBrwChild() } ) and TXBrowse():new() , but no dialog is created.

Frank

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Fri Aug 12, 2011 08:25 AM
Not recommended:
Code (fw): Select all Collapse
TXBrowse():new()


Recommended by FW
Code (fw): Select all Collapse
TXBrows():new()


TXBrows( bChild ) is now obsolete
Instead use :
SetXBrowse( bChild )

If we use command syntax, we never fail. They are correctly translated by FWH
Example:
SET XBROWSE TO TXBrwChild()
After this statement,
@ r.c XBROWSE or REDEFINE XBROWSE commands automatically use TXBrwChild.

Alternatively, if we want to use a particular child class in a single case, we need not SET XBROWSE ....

Instead:
@ r,c XBROWSE <clauses> CLASS TXBrwChild()

The child class is used only for this browse.
Regards



G. N. Rao.

Hyderabad, India
Posts: 55
Joined: Fri Jul 08, 2011 06:43 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Fri Aug 12, 2011 08:44 AM
nages,

I have FWH 8.10 , and try as described in whatsnew :

Code (fw): Select all Collapse
....
TXBrows( {|| MyTXBrowse() } )
......
oBrw := TXBrows():New( oDlg )

*******************************************
Class MyTXBrowse FROM TxBrowse
// Here i will change and add some methods from TXBrwColumn
// Now i suppose all is inherited from txbrowse
ENDCLASS


But i got 'can create dialog'

What is wrong ?
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Fri Aug 12, 2011 08:50 AM

If you create the dialog and browse from source code it works.

But if you are creating dialog and browse from resources, then you should specify the childbrowse name for the control in the rc file instead of txbrowse.

Regards



G. N. Rao.

Hyderabad, India
Posts: 55
Joined: Fri Jul 08, 2011 06:43 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Fri Aug 12, 2011 08:59 AM

Nages,

Thank you for the quick response , it works.

Frank

Posts: 55
Joined: Fri Jul 08, 2011 06:43 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Fri Aug 12, 2011 10:35 AM
NAges ,

Sory , it seems that i was to fast. I made a test with as goal to switch between MyTxbrowse and txbrowse.
(the goal is that only in the first one ocol:edit is modifyed in MyEdit)

This test has two items in the menu : 'Browse with My Browse ' and 'browse with txbrowse'

The first time both works , but after that selecting the other gives a error

Code (fw): Select all Collapse
# include "fivewin.ch"
# include "xbrowse.ch"
FUNCTION MAIN()
***********************
LOCAL oWnd
TXBrows( {|| MyTXBrowse() } )
DEFINE WINDOW oWnd TITLE "Change method Edit" ;
MENU BuildMenu( oWnd ) MDI ;
MENUINFO 3
ACTIVATE WINDOW oWnd
return nil
//----------------------------------------------------------------------------//
function BuildMenu( oWnd )
local oMenu
MENU oMenu
MENUITEM "Browse with My Browse";
ACTION EditMyBrowse( oWnd )
MENUITEM "Browse with TxBrowse";
ACTION EditTxBrowse( oWnd )
ENDMENU
return oMenu
RETURN
********************************************************************************************************************************
PROC EditMyBrowse(oWnd)
**************
LOCAL Arr := {{"Row1 , col1" , "Row 1 , Col2"},{"Row2 , col1" , "Row 2 , Col2"}}
LOCAL oDlg , oBrw , i
DEFINE DIALOG oDlg RESOURCE "TEST" OF oWnd
oBrw := TXBrows():New( oDlg )
oBrw:CreateFromResource( 101 )
oBrw:nMarqueeStyle := 3
oBrw:lFastEdit := .T.
oBrw:SetArray( Arr )
__objModMethod(oBrw:aCols[1],"Edit",@MyEdit())
oBrw:aCols[ 1 ]:nEditType := 1 // Fastedit !!!
oBrw:aCols[ 2 ]:nEditType := 1 // Fastedit !!!
ACTIVATE DIALOG oDlg
RETURN
****************************************************
PROC EditTxBrowse(oWnd)
**********************
LOCAL Arr := {{"Row1 , col1" , "Row 1 , Col2"},{"Row2 , col1" , "Row 2 , Col2"}}
LOCAL oDlg , oBrw , i
DEFINE DIALOG oDlg RESOURCE "TEST1"
TXBrows( {|| TXBrowse() } )
oBrw := TXBrows():New( oDlg )
oBrw:CreateFromResource( 101 )
oBrw:nMarqueeStyle := 3
oBrw:lFastEdit := .T.
oBrw:SetArray( Arr )
oBrw:aCols[ 1 ]:nEditType := 1 // Fastedit !!!
oBrw:aCols[ 2 ]:nEditType := 1 // Fastedit !!!
ACTIVATE DIALOG oDlg
**************************************************
Class MyTXBrowse FROM TxBrowse
ENDCLASS
****************************************************
FUNCTION MyEdit()
? "MyEdit"
RETURN
****************************************************
/*
TEST DIALOG 6, 15, 450, 227
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "TXBrowse demo"
FONT 8, "MS Sans Serif"
{
CONTROL "", 101, "MyTXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 4, 5, 328 , 202
PUSHBUTTON "OK", 300 , 252, 211, 50, 14
}

TEST1 DIALOG 6, 15, 450, 227
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "TXBrowse demo"
FONT 8, "MS Sans Serif"
{
CONTROL "", 101, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 4, 5, 328 , 202
PUSHBUTTON "OK", 300 , 252, 211, 50, 14
}
*/
Posts: 55
Joined: Fri Jul 08, 2011 06:43 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Fri Aug 12, 2011 01:21 PM

The only solution i found to change and restore TXBrwColumn:Edit with a function is :

1) After the browse is created with his columns :

__objModMethod(oBrw:aCols[1],"Edit",@MyOwnEdit( ... ))

2) In Xbrowse we make a function (copy from Txbrwcolumn:edit) MyTxBrowEdit(nKey) , and add LOCAL self := Hb_QSelf

Now we can restore with
__objModMethod(oBrw:aCols[1],"Edit",@TxBrowEdit(nKey))

Xbrowse.prg must be linked in.

BUT : Bad solution , we have to touch source from FWH

Who has a better solution ???????

Frank

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: TXBrwColumn : changing and restoring a method
Posted: Fri Aug 12, 2011 01:44 PM
Hello

in child class, create a DATA lSuper, set TRUE to use original Method edit or FALSE to use your own method edit

like this

Code (fw): Select all Collapse
METHOD MyEdit()

if ::lSuper
   return ::Super:edit()
endif
...
Posts: 55
Joined: Fri Jul 08, 2011 06:43 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Sat Aug 13, 2011 06:35 AM
Daniel Garcia-Gil wrote:Hello

in child class, create a DATA lSuper, set TRUE to use original Method edit or FALSE to use your own method edit

like this

Code (fw): Select all Collapse
METHOD MyEdit()

if ::lSuper
   return ::Super:edit()
endif
...

Daniel ,

I tried your solution , but it doesn't work.
After 'OVERRIDE METHOD Edit IN CLASS TxbrwColumn WITH MyEdit' , every call to TxbrwColumn:edit is translated in MyEdit , so we become a endless loop.
Maybe i have not understood what you mean , here is the code :
Code (fw): Select all Collapse
# include "fivewin.ch"
# include "xbrowse.ch"
# include "Common.ch"
# include "HbClass.ch"

FUNCTION MAIN()
***********************
LOCAL oWnd
EXTEND CLASS TxBrowse WITH DATA lMyEdit
OVERRIDE METHOD Edit IN CLASS TxbrwColumn WITH MyEdit
DEFINE WINDOW oWnd TITLE "Change method Edit" ;
MENU BuildMenu( oWnd ) MDI ;
MENUINFO 3
ACTIVATE WINDOW oWnd
return nil
//----------------------------------------------------------------------------//
function BuildMenu( oWnd )
local oMenu
MENU oMenu
MENUITEM "Browse with My Browse";
ACTION EditMyBrowse( oWnd , .T.)
MENUITEM "Browse with TxBrowse";
ACTION EditMyBrowse( oWnd , .F.)
ENDMENU
return oMenu
RETURN
********************************************************************************************************************************
PROC EditMyBrowse(oWnd , lMyEdit)
***********************
LOCAL Arr := {{"Row1 , col1" , "Row 1 , Col2"},{"Row2 , col1" , "Row 2 , Col2"}}
LOCAL oDlg , oBrw , i
DEFINE DIALOG oDlg RESOURCE "TEST" OF oWnd
oBrw := TXBrows():New( oDlg )
oBrw:CreateFromResource( 101 )
oBrw:nMarqueeStyle := 3
oBrw:lFastEdit := .T.
oBrw:lMyEdit := lMyEdit
oBrw:SetArray( Arr )
oBrw:aCols[ 1 ]:nEditType := 1
oBrw:aCols[ 2 ]:nEditType := 1
ACTIVATE DIALOG oDlg
oBrw:end()
RETURN
****************************************************
//PROC MyEdit(nKey)
PROC MyEdit(nKey)
LOCAL Self := Hb_QSelf()
IF ! ::oBrw:lMyEdit
  RETURN ::Edit(nKey) //Calls MyEdit ........ endless loop 
END
? "MyEdit" , nKey
RETURN
****************************************************
/*
TEST DIALOG 6, 15, 450, 227
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "TXBrowse demo"
FONT 8, "MS Sans Serif"
{
CONTROL "", 101, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 4, 5, 328 , 202
PUSHBUTTON "OK", 300 , 252, 211, 50, 14
}
*/
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Sat Aug 13, 2011 07:09 AM
Because you are not using COMMAND syntax for creating XBrowse, it should be very simple for you to switch between Parent and Child classes on the fly.

After seeing some parts of your code above, your implementation of the derived class seems defective. Follow the template give in the samples folder. In particular
Code (fw): Select all Collapse
   CLASSDATA lRegistered AS LOGICAL // used internally

is essential in the derived class. I do not see it in your above code,

I guess you want to override the Edit method of the column class. If so follow this template:
Code (fw): Select all Collapse
//------------------------------------------------------------------//

CLASS MyBrowse FROM TXBrowse

   // please note these following two lines
   CLASSDATA lRegistered AS LOGICAL // This is compulsory for derived classes
   DATA bColClass INIT { || MyXBrCol() }

   METHOD New( oWnd ) CONSTRUCTOR  // optional.

ENDCLASS

METHOD New( oWnd ) CLASS MyBrowse

   Super:New( oWnd )

return Self

CLASS MyXbrCol FROM TXBrwColumn

   METHOD Edit()

ENDCLASS

METHOD Edit() CLASS MyXBrCol

   MsgInfo( "My Derived Class"

return Self


I do not have 8.10 version with me now.
After implementing the above derived class, you do not have to use TXBrows( { || ... } )

In the function where you want to use original class
use
TXBrowse():New( oWnd )
and use the rc file where the browse name is "TXBrowse"

When you want to use derived class:
use
MyBrowse():New( oWnd )
and use rc file where the browse's name is "MBrowse"

Do not do any thing more than this.
If it does not work still, please post the most simplified code here.

Note: I do not have 8.10 version with me. I recommended based on my memory.
Regards



G. N. Rao.

Hyderabad, India
Posts: 55
Joined: Fri Jul 08, 2011 06:43 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Sun Aug 14, 2011 08:39 AM

Nages ,

Thank you very much , as always you are a great help.

I try to change edit from xbrowse , each cell from a row can be edited with a control defined in the program (and rc-file). So it is possible to have get's , say's , checkbox , DatePicker , ....

See viewtopic.php?f=3&t=10981&hilit=xbrowse+line+line+edit#p53900

Frank

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TXBrwColumn : changing and restoring a method
Posted: Sun Aug 14, 2011 12:41 PM

Glad you are able to use derived classes intermixed with regular txbrowse in your application now. Now you can implement the edits the way you want.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion