TXBrwColumn : changing and restoring a method

TXBrwColumn : changing and restoring a method

Postby Demont Brecht » Fri Aug 12, 2011 8: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
Demont Brecht
 
Posts: 55
Joined: Fri Jul 08, 2011 6:43 am

Re: TXBrwColumn : changing and restoring a method

Postby nageswaragunupudi » Fri Aug 12, 2011 8:25 am

Not recommended:
Code: Select all  Expand view
TXBrowse():new()


Recommended by FW
Code: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: TXBrwColumn : changing and restoring a method

Postby Demont Brecht » Fri Aug 12, 2011 8:44 am

nages,

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

Code: Select all  Expand view

....
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 ?
Demont Brecht
 
Posts: 55
Joined: Fri Jul 08, 2011 6:43 am

Re: TXBrwColumn : changing and restoring a method

Postby nageswaragunupudi » Fri Aug 12, 2011 8: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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: TXBrwColumn : changing and restoring a method

Postby Demont Brecht » Fri Aug 12, 2011 8:59 am

Nages,

Thank you for the quick response , it works.

Frank
Demont Brecht
 
Posts: 55
Joined: Fri Jul 08, 2011 6:43 am

Re: TXBrwColumn : changing and restoring a method

Postby Demont Brecht » 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: Select all  Expand view

# 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
}
*/

 
Demont Brecht
 
Posts: 55
Joined: Fri Jul 08, 2011 6:43 am

Re: TXBrwColumn : changing and restoring a method

Postby Demont Brecht » Fri Aug 12, 2011 1: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
Demont Brecht
 
Posts: 55
Joined: Fri Jul 08, 2011 6:43 am

Re: TXBrwColumn : changing and restoring a method

Postby Daniel Garcia-Gil » Fri Aug 12, 2011 1: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: Select all  Expand view
METHOD MyEdit()

if ::lSuper
   return ::Super:edit()
endif
...
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: TXBrwColumn : changing and restoring a method

Postby Demont Brecht » Sat Aug 13, 2011 6: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: Select all  Expand view
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: Select all  Expand view

# 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
}
*/

 
Demont Brecht
 
Posts: 55
Joined: Fri Jul 08, 2011 6:43 am

Re: TXBrwColumn : changing and restoring a method

Postby nageswaragunupudi » Sat Aug 13, 2011 7: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: Select all  Expand view
  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: Select all  Expand view
//------------------------------------------------------------------//

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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: TXBrwColumn : changing and restoring a method

Postby Demont Brecht » Sun Aug 14, 2011 8: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
Demont Brecht
 
Posts: 55
Joined: Fri Jul 08, 2011 6:43 am

Re: TXBrwColumn : changing and restoring a method

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 95 guests