Custom xBrowse

Custom xBrowse

Postby ryugarai27 » Thu Mar 15, 2012 5:11 am

Hi All,

I've created a window with xbrowse control using REDEFINE XBROWSE... I've also created a class for customized xBrowse and created a dialog using this class int the later part of the program. However, when i used the class, i always get an error Fivewin/3: Cannot create dialog box ::Argument NIL.

Changing the code to use both xBrowse ( without using customized class ) or vice versa ( using both customized xbrowse ) seems fine...

Could I not use xBrowse and customized xBrowse together?

Below is the customized xbrowse class:


#include "fivewin.ch"
#include "xbrowse.ch"

CLASS CustomBrowse FROM TXBrowse

DATA oWnd
DATA oBrow
DATA aFormat
DATA lArray

METHOD New( oWnd ) CONSTRUCTOR
METHOD KeyDown()
METHOD SetFormat( aFormat )

ENDCLASS

//------------------------------------------------------------------------------
METHOD New( oWnd ) CLASS CustomBrowse

::oBrow := Super():New( oWnd )
::aFormat := {}
::oWnd := oWnd

WITH OBJECT ::oBrow
:nRowHeight := 24
:nHeaderHeight := 26
END

RETURN ( Self )

//------------------------------------------------------------------------------
METHOD KeyDown( nKey, nFlags ) CLASS CustomBrowse
LOCAL oErr

TRY

DO CASE
CASE nKey == VK_INSERT

//::AddRecord()
Super:Refresh()

CASE nKey == VK_DELETE

//::DeleteRecord()

CASE nKey == VK_UP
// Msginfo( 'UP' )
CASE nKey == VK_DOWN
// Msginfo( 'Down' )
CASE nKey == VK_RETURN

OTHERWISE
// ::aData[::oBrow:nArrayAt, Len(::aData[::oBrow:nArrayAt])]:lMod := .T. // set current object lModified to .T.
ENDCASE



CATCH oErr
IF ValType( oErr ) == 'O'

MsgAlert(' ::SubSystem ' + cvaltoChar( oErr: Subsystem ) + CRLF + ;
' ::SubCode ' + cvaltoChar( oErr: SubCode ) + CRLF + ;
' ::Operation ' + cvaltoChar( oErr: Operation ) + CRLF + ;
' ::Description ' + cvaltoChar( oErr: Description ) + CRLF + ;
' ::Arguments ' + cvaltoChar( oErr: Args ), 'KeyDown' )

END
END

return super:keyDown( nKey, nFlags )

//------------------------------------------------------------------------------
METHOD SetFormat( aFormat ) CLASS CustomBrowse

LOCAL nLim, o, oErr
STATIC i := 1

IF ValType( aFormat ) == 'A'
::aFormat := aFormat
END

nLim := Len( ::oBrow:aCols )

TRY
FOR i := 1 TO nLim
::oBrow:aCols[i]:cHeader := aFormat[i, 1]
::oBrow:aCols[i]:nHeadStrAlign := aFormat[i, 2]
::oBrow:aCols[i]:lAllowSizing := aFormat[i, 3]
::oBrow:aCols[i]:nWidth := aFormat[i, 4]
::oBrow:aCols[i]:nDataStrAlign := aFormat[i, 5]
// ::oBrow:aCols[i]:lFastEdit := aFormat[i, 11]
// ::oBrow:lColDividerComplete := .t.

NEXT i

CATCH oErr
IF ValType( oErr ) == 'O'

MsgAlert(' ::SubSystem ' + cvaltoChar( oErr: Subsystem ) + CRLF + ;
' ::SubCode ' + cvaltoChar( oErr: SubCode ) + CRLF + ;
' ::Operation ' + cvaltoChar( oErr: Operation ) + CRLF + ;
' ::Description ' + cvaltoChar( oErr: Description ) + CRLF + ;
' ::Arguments ' + cvaltoChar( oErr: Args ), 'SetFormat' )

END
END

RETURN ( nil )



thanks,
ryugarai27
User avatar
ryugarai27
 
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines

Re: Custom xBrowse

Postby StefanHaupt » Thu Mar 15, 2012 8:34 am

Try to use the the real name of the class in your dialog definition

for TXBrowse
Code: Select all  Expand view
CONTROL "", 10, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL, 4, 4, 168, 110


for your own class
Code: Select all  Expand view
CONTROL "", 10, "CustomBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL, 4, 4, 168, 110
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Custom xBrowse

Postby ryugarai27 » Thu Mar 15, 2012 9:59 am

Hi Stefan,

Thanks for quick response. However, What i needed is to pop-up a dialog with customized browse in it ( using the class i created ).

Below is a test program to show u the error i encountered. Below code produces the error, however, when i tried changing the lines

oBrow := CustomBrowse():New( oDlg )

into

@ 5,5 XBROWSE oBrow SIZE 700,400 PIXEL OF oDlg AUTOCOLS AUTOSORT // not using customized xbrowse

the program seems fine...I still can't find why the error persists when using both xbrowse and customized xbrowse...

Thanks,

ryugarai27


// code proper.............................................................
#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()
local oDlg, oBrow, oBrow1, oWnd, oBtn, oBar

use customer alias 'cust'

DEFINE WINDOW oWnd TITLE 'Test' MDI PIXEL MENU TMenu():New(); // MENU ::BuildMenu();

DEFINE BUTTONBAR oBar OF oWnd SIZE 80, 65 3DLOOK

DEFINE BUTTON oBtn OF oBar; //FILENAME "Z:\FIVEWIN\POS2\images\64x64\Keys.bmp";
PROMPT "Test";
ADJUST NOBORDER;
ACTION uCustBrow( oWnd )

@ 5,5 XBROWSE oBrow1 SIZE 700,400 PIXEL OF oWnd:oWndClient ;
AUTOCOLS AUTOSORT


oBrow1:cAlias := 'cust'

oBrow1:CreateFromCode()


ACTIVATE WINDOW oWnd MAXIMIZED;
// ON INIT ( oWnd:oClient := oBrow1, oWnd:Resize() )

return nil

//------------------------------------------------------------------------------
FUNCTION uCustBrow( oWnd )
LOCAL oDlg, oBrow, oErr
LOCAL a := { { "one","two","three" } }

TRY

DEFINE DIALOG oDlg SIZE 500,480 OF oWnd

oBrow := CustomBrowse():New( oDlg )

// @ 5,5 XBROWSE oBrow SIZE 700,400 PIXEL OF oDlg AUTOCOLS AUTOSORT
oBrow:SetArray( a )
oBrow:CreateFromCode()

ACTIVATE DIALOG oDlg

CATCH oErr
IF ValType( oErr ) == 'O'

MsgAlert(' ::SubSystem ' + cvaltoChar( oErr: Subsystem ) + CRLF + ;
' ::SubCode ' + cvaltoChar( oErr: SubCode ) + CRLF + ;
' ::Operation ' + cvaltoChar( oErr: Operation ) + CRLF + ;
' ::Description ' + cvaltoChar( oErr: Description ) + CRLF + ;
' ::Arguments ' + cvaltoChar( oErr: Args ), 'uCustBrow()' )

END
END


RETURN ( nil )

//------------------------------------------------------------------------------
CLASS CustomBrowse FROM TXBrowse

DATA oWnd
DATA oBrow
DATA aFormat
DATA lArray

METHOD New( oWnd ) CONSTRUCTOR
METHOD KeyDown()
METHOD SetFormat( aFormat )

ENDCLASS

//------------------------------------------------------------------------------
METHOD New( oWnd ) CLASS CustomBrowse

::oBrow := Super():New( oWnd )
::aFormat := {}
::oWnd := oWnd

WITH OBJECT ::oBrow
:nRowHeight := 24
:nHeaderHeight := 26
END

RETURN ( Self )

//------------------------------------------------------------------------------
METHOD KeyDown( nKey, nFlags ) CLASS CustomBrowse
LOCAL oErr

TRY

DO CASE
CASE nKey == VK_INSERT

//::AddRecord()
Super:Refresh()

CASE nKey == VK_DELETE

//::DeleteRecord()

CASE nKey == VK_UP
// Msginfo( 'UP' )
CASE nKey == VK_DOWN
// Msginfo( 'Down' )
CASE nKey == VK_RETURN

OTHERWISE
// ::aData[::oBrow:nArrayAt, Len(::aData[::oBrow:nArrayAt])]:lMod := .T. // set current object lModified to .T.
ENDCASE



CATCH oErr
IF ValType( oErr ) == 'O'

MsgAlert(' ::SubSystem ' + cvaltoChar( oErr: Subsystem ) + CRLF + ;
' ::SubCode ' + cvaltoChar( oErr: SubCode ) + CRLF + ;
' ::Operation ' + cvaltoChar( oErr: Operation ) + CRLF + ;
' ::Description ' + cvaltoChar( oErr: Description ) + CRLF + ;
' ::Arguments ' + cvaltoChar( oErr: Args ), 'KeyDown' )

END
END

return super:keyDown( nKey, nFlags )

//------------------------------------------------------------------------------
METHOD SetFormat( aFormat ) CLASS CustomBrowse

LOCAL nLim, o, oErr
STATIC i := 1

IF ValType( aFormat ) == 'A'
::aFormat := aFormat
END

nLim := Len( ::oBrow:aCols )

TRY
FOR i := 1 TO nLim
::oBrow:aCols[i]:cHeader := aFormat[i, 1]
::oBrow:aCols[i]:nHeadStrAlign := aFormat[i, 2]
::oBrow:aCols[i]:lAllowSizing := aFormat[i, 3]
::oBrow:aCols[i]:nWidth := aFormat[i, 4]
::oBrow:aCols[i]:nDataStrAlign := aFormat[i, 5]
// ::oBrow:aCols[i]:lFastEdit := aFormat[i, 11]
// ::oBrow:lColDividerComplete := .t.

NEXT i

CATCH oErr
IF ValType( oErr ) == 'O'

MsgAlert(' ::SubSystem ' + cvaltoChar( oErr: Subsystem ) + CRLF + ;
' ::SubCode ' + cvaltoChar( oErr: SubCode ) + CRLF + ;
' ::Operation ' + cvaltoChar( oErr: Operation ) + CRLF + ;
' ::Description ' + cvaltoChar( oErr: Description ) + CRLF + ;
' ::Arguments ' + cvaltoChar( oErr: Args ), 'SetFormat' )

END
END

RETURN ( nil )
User avatar
ryugarai27
 
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines

Re: Custom xBrowse

Postby StefanHaupt » Fri Mar 16, 2012 8:03 am

ryugarai27,

look in the include file xbrowse.ch, how the original class is used and how the object is created (function xBrowseNew (...) ).

You can try to create your own function for your own class.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Custom xBrowse

Postby nageswaragunupudi » Sat Mar 17, 2012 6:07 am

#1. While using Inherited XBrowse, you should use the name of your class in the RC file instead of TXBrowse, exactly as advised by Mr. StefanHaupt in his earlier post.

#2. Your inherited class is not correctly coded. There is a sample in fwh\samples folder. Please use it as template.

#3. While using the inherited class in your program, use this syntax:
REDEFINE XBROWSE oBrw <all your clauses> CLASS CustomBrowse()

Please note the last clause CLASS <yourclassname>()

#4. After doing this, if you still have problems please post a brief version of your derived class here. Important part you need to post are the full class declaration ( from CLASS ..... to ENDCLASS ) and atleast your METHOD New() in full.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Custom xBrowse

Postby fraxzi » Sat Mar 17, 2012 7:37 am

OT:

Erick how are you?
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: Custom xBrowse

Postby ryugarai27 » Fri Mar 23, 2012 12:48 am

Hi Rao, Stefan,

Thanks for replies, I still cannot find what's wrong with my code...

1. First, i did'nt use an RC file to create my dialogs and controls.
2. I coded the first browse using original class TXBrowse, while i coded the second browse using the class CustmBrowse inherited from class TXBrowse. That's
because i want to override the method Keydown() for the second browse.
3. Class CustomBrowse has only 1 method which is KeyDown(), all other methods are automatically inherited from TXBrowse including method New()

I believe my codings were fine, if not, kindly enlighten me where i went wrong.

Below is my test code, including class CustomBrowse. Please test at your end if the same error persists.


// ....................................main program..........................//

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()
local oDlg, oBrow1, oWnd, oBtn, oBar

use customer alias 'cust'
DEFINE WINDOW oWnd TITLE 'Test' MDI PIXEL MENU TMenu():New()
DEFINE BUTTONBAR oBar OF oWnd SIZE 80, 65 3DLOOK
DEFINE BUTTON oBtn OF oBar; //FILENAME "Z:\FIVEWIN\POS2\images\64x64\Keys.bmp";
PROMPT "Test";
ADJUST NOBORDER;
ACTION uCustBrow( oWnd )

@ 0,0 XBROWSE oBrow1 SIZE 900,400 PIXEL OF oWnd:oWndClient ;
AUTOCOLS AUTOSORT
oBrow1:cAlias := 'cust'
oBrow1:CreateFromCode()

ACTIVATE WINDOW oWnd MAXIMIZED;

return nil

//------------------------------------------------------------------------------
FUNCTION uCustBrow( oWnd )
LOCAL oDlg, oBrow, oErr
LOCAL a := { { "one","two","three" } }

TRY

DEFINE DIALOG oDlg SIZE 500,480 OF oWnd

oBrow := CustomBrowse():New( oDlg )
oBrow:SetArray( a )
oBrow:CreateFromCode()

ACTIVATE DIALOG oDlg

CATCH oErr
IF ValType( oErr ) == 'O'

MsgAlert(' ::SubSystem ' + cvaltoChar( oErr: Subsystem ) + CRLF + ;
' ::SubCode ' + cvaltoChar( oErr: SubCode ) + CRLF + ;
' ::Operation ' + cvaltoChar( oErr: Operation ) + CRLF + ;
' ::Description ' + cvaltoChar( oErr: Description ) + CRLF + ;
' ::Arguments ' + cvaltoChar( oErr: Args ), 'uCustBrow()' )

END
END


//------------------------ CLASS CustomBrowse ...........................//
CLASS CustomBrowse FROM TXBrowse

METHOD KeyDown()

ENDCLASS

//------------------------------------------------------------------------------
METHOD KeyDown( nKey, nFlags ) CLASS CustomBrowse

DO CASE
CASE nKey == VK_INSERT
Super:Refresh()
CASE nKey == VK_DELETE
//::DeleteRecord()
CASE nKey == VK_UP
// Msginfo( 'UP' )
CASE nKey == VK_DOWN
// Msginfo( 'Down' )
CASE nKey == VK_RETURN

OTHERWISE

ENDCASE

return super:keyDown( nKey, nFlags )
User avatar
ryugarai27
 
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines

Re: Custom xBrowse

Postby ryugarai27 » Fri Mar 23, 2012 1:07 am

Hi Fraxzi,

Very much fine. Just coding some...to refresh...hehehe

How's life there? What projects currently are you into?
User avatar
ryugarai27
 
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines

Re: Custom xBrowse

Postby nageswaragunupudi » Fri Mar 23, 2012 1:52 am

The above program is modified to make it work
Code: Select all  Expand view
// ....................................main program..........................//

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()
local oDlg, oBrow1, oWnd, oBtn, oBar

   use customer alias 'cust'
   DEFINE WINDOW oWnd TITLE 'Test' MDI PIXEL MENU TMenu():New()
   DEFINE BUTTONBAR oBar OF oWnd SIZE 80, 65 3DLOOK
   DEFINE BUTTON oBtn OF oBar; //FILENAME "Z:\FIVEWIN\POS2\images\64x64\Keys.bmp";
   PROMPT "Test";
   ADJUST NOBORDER;
   ACTION uCustBrow( oWnd )

   @ 0,0 XBROWSE oBrow1 SIZE 900,400 PIXEL OF oWnd:oWndClient ;
   AUTOCOLS ALIAS "CUST" AUTOSORT // Let this command know alias to browse
   // oBrow1:cAlias := 'cust'  // better to specify in the command
   oBrow1:CreateFromCode()

   ACTIVATE WINDOW oWnd MAXIMIZED;

return nil

//------------------------------------------------------------------------------
FUNCTION uCustBrow( oWnd )
   LOCAL oDlg, oBrow, oErr
   LOCAL a := { { "one","two","three" }, { "four", "five", "six" }, { "seven", "eight", "nine" } }

//   TRY

   DEFINE DIALOG oDlg SIZE 500,480 OF oWnd
/*
   oBrow := CustomBrowse():New( oDlg )
   oBrow:SetArray( a )
*/

   @ 10,10 XBROWSE oBrow SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS ARRAY a CELL LINES NOBORDER ;
      CLASS CustomBrowse()

   oBrow:CreateFromCode()

   ACTIVATE DIALOG oDlg

return nil // added

/*
   CATCH oErr
   IF ValType( oErr ) == 'O'

   MsgAlert(' ::SubSystem ' + cvaltoChar( oErr: Subsystem ) + CRLF + ;
   ' ::SubCode ' + cvaltoChar( oErr: SubCode ) + CRLF + ;
   ' ::Operation ' + cvaltoChar( oErr: Operation ) + CRLF + ;
   ' ::Description ' + cvaltoChar( oErr: Description ) + CRLF + ;
   ' ::Arguments ' + cvaltoChar( oErr: Args ), 'uCustBrow()' )

   END
   END
*/


//------------------------ CLASS CustomBrowse ...........................//
CLASS CustomBrowse FROM TXBrowse

   CLASSDATA lRegistered AS LOGICAL INIT .f.

   METHOD KeyDown()

ENDCLASS

//------------------------------------------------------------------------------
METHOD KeyDown( nKey, nFlags ) CLASS CustomBrowse

   DO CASE
   CASE nKey == VK_INSERT
      ASize( ::aArrayData, Len( ::aArrayData ) + 1 )
      AIns(  ::aArrayData, ::nArrayAt, { '', '', '' } )
      ::Refresh()
   CASE nKey == VK_DELETE
      //::DeleteRecord()
      if Len( ::aArrayData ) > 0
         ADel( ::aArrayData, ::nArrayAt )
         ASize( ::aArrayData, Len( ::aArrayData ) - 1 )
         ::Refresh()
      endif
   CASE nKey == VK_UP
      // Msginfo( 'UP' )
   CASE nKey == VK_DOWN
      // Msginfo( 'Down' )
   CASE nKey == VK_RETURN

   OTHERWISE

   ENDCASE

return super:keyDown( nKey, nFlags )

//----------------------------------------------------------------------------//
 


Please also indicate the version of FWH an (x)Harbour you are using.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Custom xBrowse

Postby ryugarai27 » Fri Mar 23, 2012 2:47 am

Hi Rao,

Thanks for quick response. I'm using an older version, FWH 9.01 and xHb 1.1. Your code generates an error on this line:

@ 10,10 XBROWSE oBrow SIZE -10,-10 PIXEL OF oDlg ;
AUTOCOLS ARRAY a CELL LINES NOBORDER ;
CLASS CustomBrowse()

it seems that CLASS clause is not yet supported in the version i am using. is there a possible workaround to to this error for the meantime until i get an updated version of FWH?

thanks..ryugarai27
User avatar
ryugarai27
 
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines

Re: Custom xBrowse

Postby nageswaragunupudi » Fri Mar 23, 2012 5:39 am

Instead of
Code: Select all  Expand view
  @ 10,10 XBROWSE oBrow SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS ARRAY a CELL LINES NOBORDER ;
      CLASS CustomBrowse()
 

Please retain your original code:
Code: Select all  Expand view
  oBrow := CustomBrowse():New( oDlg )
   oBrow:SetArray( a )
 

This is enough to make it work.

You may like to add assignments of top,left,width,height and other datas pf the object suitably.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Custom xBrowse

Postby ryugarai27 » Fri Mar 23, 2012 8:45 am

Hi Rao,

Thanks! The changes works perfectly.

The line :

CLASSDATA lRegistered AS LOGICAL INIT .f.

solves the problem.

regards,
ryugarai27
User avatar
ryugarai27
 
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines

Re: Custom xBrowse

Postby fraxzi » Mon Mar 26, 2012 8:56 am

ryugarai27 wrote:Hi Fraxzi,

Very much fine. Just coding some...to refresh...hehehe

How's life there? What projects currently are you into?



Erick,

Why modify an already working class.. anyway.. hehehe.. to each his own.

I'm doing biometric-time attendance system already deployed and working live.. both in LAN/WAN configuration.. also considering 'remote application server' for web portal
so FWH apps runs like within LAN.. accessed by web browser.. sounds great.. considering tons of application server out there.. top of my lis is '2X ApplicationServer XG' or just plain windows terninal services..

Glad to hear from you partner! keep up with what you are doing in FWH and xHarbour... if there's a better language for xBase.. this is the most cost effective... :lol:
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 54 guests