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
TXBrowse():new()
TXBrows():new()
....
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
# 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
}
*/
METHOD MyEdit()
if ::lSuper
return ::Super:edit()
endif
...
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: Select all Expand view
METHOD MyEdit()
if ::lSuper
return ::Super:edit()
endif
...
# 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
}
*/
CLASSDATA lRegistered AS LOGICAL // used internally
//------------------------------------------------------------------//
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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 92 guests