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
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
ENDCLASSIf 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.
Nages,
Thank you for the quick response , it works.
Frank
# 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
}
*/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
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
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 SelfNages ,
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
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.