Page 1 of 1

2 xbrowse is strange behavier!

PostPosted: Sun Apr 13, 2008 5:38 pm
by dutch
Dear Antonio,

I have problem with 2 xbrowse in one dialog. I've used TWbrowse for this dialog without problem. This is the following code and .RC file.
TWbrowse is work ok.
Image
TXbrowse is not work.
Image

Code: Select all  Expand view
#include 'fivewin.ch'
#include 'xbrowse.ch'

Function main
local oDlg, oBrw1, oBrw2, oSay

Request DBFCDX, DBFFPT
RddSetDefault('DBFCDX')

USE CCRCODE ALIAS SUB SHARED NEW
SUB->(DBSETORDER(1))
SUB->(DbGoTop())

USE CCRCODE ALIAS MAN SHARED NEW
MAN->(DBSETORDER(1))
  MAN->(cmxSetScope(0,'M  '))
  MAN->(cmxSetScope(1,'M  '))
  MAN->(Dbgotop())

DEFINE DIALOG oDlg RESOURCE 'CONMCODE'

     SELECT('MAN')
     REDEFINE XBROWSE oBrw1 FIELDS MAN->COD_CODE, MAN->COD_DESC ;
             HEADERS TE('????','Code'), TE('??????','Description') ;
            FIELDSIZES 50, 180 ;
            UPDATE ;
            ID 101

   oBrw1:bChange := { || ( Brow_sCode( oBrw1 , oBrw2 , .F. ), oBrw1:Refresh() ) }

    SELECT('SUB')
     SUB->(DBseek(MAN->COD_CODE))
     REDEFINE XBROWSE oBrw2 FIELDS SUB->COD_CODE, SUB->COD_DESC ;
            HEADERS TE('????','Code'), TE('??????','Description') ;
            FIELDSIZES 50, 180 ;
            UPDATE ;
            ID 102

ACTIVATE DIALOG oDlg ON INIT (Eval( oBrw1:bChange ) ) RESIZE16

Close all
SET RESOURCES TO
ResAllFree()
return .T.

function TE(T,E)
return E

*-----------------*
Function Brow_sCode( oBrw1 , oBrw2 , lDelete )
Select SUB

SUB->(cmxClrScope(0))
SUB->(cmxClrScope(1))

if lDelete
   MsgAlert( 'Code : '+MAN->COD_CODE+' was deleted' )
end

SUB->(DbSeek(MAN->COD_CODE))
SUB->(cmxSetScope(0,MAN->COD_CODE))
SUB->(cmxSetScope(1,MAN->COD_CODE))

if SUB->(cmxKeyCount()) > 0
   oBrw2:GoTop()
end
oBrw2:Refresh(.T.)

SELECT('MAN')
oBrw1:Refresh()
return nil


Function cmxSetScope( nScope, xVal )
return if(PCount() <= 1, OrdScope( nScope ), OrdScope( nScope, xVal ))

Function cmxClrScope( nScope )
return OrdScope( nScope, Nil)

Function cmxKeyNo()
return OrdKeyNo()

Function cmxKeyCount()
return OrdKeyCount()

Function cmxKeyCoun()
return OrdKeyCount()

Function cmxKeyGoTo(nKey)
return OrdKeyGoTo(nKey)

/*
CONMCODE DIALOG 6, 15, 393, 203
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "User Define Pick Box"
FONT 8, "MS Sans Serif"
{
CONTROL "", 101, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 2, 14, 190, 152
CONTROL "", 102, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 199, 14, 190, 152
LTEXT "Main Group Code", 109, 2, 2, 65, 10
LTEXT "Pick Up Code", 110, 199, 2, 65, 10
PUSHBUTTON "&New Group", 11, 2, 169, 45, 30
PUSHBUTTON "&Edit Group", 12, 48, 169, 45, 30
PUSHBUTTON "&Delete Group", 13, 94, 169, 45, 30
PUSHBUTTON "Ne&w  Code", 14, 199, 169, 45, 30
PUSHBUTTON "E&dit Code", 15, 245, 169, 45, 30
PUSHBUTTON "Delete &Code", 16, 291, 169, 45, 30
CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE, 195, 2, 1, 197
}
*/

PostPosted: Sun Apr 13, 2008 7:52 pm
by James Bott
You forgot to tell use what the problem is.

Why are you redefining the names of the database functions? Is this so you don't have to change existing source code?

If this is not for an existing program, then I would strongly suggest using a database object.

James

PostPosted: Mon Apr 14, 2008 12:55 am
by nageswaragunupudi
Mr Dutch

Theoretically there should not be any difference whatever be the Browse. I would like to test your code on wbrowse and xbrowse. If you like, you may please send to my private email, a copy of your CCRCODE.DBF, CCRCODE.CDX and CCRCODE.FPT ? You may send a sample of the table instead of the actual table.

PostPosted: Mon Apr 14, 2008 2:25 am
by nageswaragunupudi
I tested with similar tables and it is working fine for me.
Code: Select all  Expand view
Function main
local oDlg, oBrw1, oBrw2, oSay

Request DBFCDX, DBFFPT
RddSetDefault('DBFCDX')

USE CCRCODE ALIAS SUB SHARED NEW
SUB->(DBSETORDER(1))
SUB->(DbGoTop())

USE MANCODE ALIAS MAN SHARED NEW
MAN->(DBSETORDER(1))
MAN->(Dbgotop())

DEFINE DIALOG oDlg RESOURCE 'CONMCODE'

REDEFINE XBROWSE oBrw1 FIELDS MAN->COD_CODE, MAN->COD_DESC ;
  HEADERS 'Code', 'Description' ;
  ALIAS "MAN" uPDATE ;
  ID 101

oBrw1:bChange := { || ( Brow_sCode( oBrw1 , oBrw2 , .F. ), oBrw1:Refresh() ) }

SUB->(DBseek(MAN->COD_CODE))
REDEFINE XBROWSE oBrw2 FIELDS SUB->COD_CODE, SUB->COD_DESC ;
       HEADERS 'Code', 'Description' ;
       ALIAS "SUB" UPDATE ;
       ID 102

ACTIVATE DIALOG oDlg ON INIT (Eval( oBrw1:bChange ) ) RESIZE16

Close all
SET RESOURCES TO
ResAllFree()

return nil

Function Brow_sCode( oBrw1 , oBrw2 , lDelete )
Select SUB


if lDelete
   MsgAlert( 'Code : '+MAN->COD_CODE+' was deleted' )
end

SUB->(OrdScope(0,MAN->COD_CODE))
SUB->(OrdScope(1,MAN->COD_CODE))
SUB->(dbGotop())

oBrw2:GoTop()
oBrw2:Refresh(.T.)
oBrw1:Refresh()

return nil

I am getting the desired results with the above code.

PostPosted: Mon Apr 14, 2008 3:05 pm
by dutch
Dear James & nageswaragunupudi,

The problem is the first browse (Main/Left) is not show correctly. It should show 4 main group but it show 1 main group with 4 lines. It has not problem with Twbrowse (the same code).

This is the sample code, database files and .RC (1 TWbrowse/ 1 TXbrowse).
http://rapidshare.com/files/107430839/samples.zip.html

nageswaragunupudi wrote:Mr Dutch

Theoretically there should not be any difference whatever be the Browse. I would like to test your code on wbrowse and xbrowse. If you like, you may please send to my private email, a copy of your CCRCODE.DBF, CCRCODE.CDX and CCRCODE.FPT ? You may send a sample of the table instead of the actual table.


Regards,
Dutch

PostPosted: Mon Apr 14, 2008 3:19 pm
by Richard Chidiak
Dutch

I had a smiliar problem with several nested xbrowse, it was fixed by adding to each browse

obrw:bBookMark := {| n | iif( n == nil,aliasxxx->(RecNo()), aliasxxx->(dbgoto(n)) ) } // Required!

In theory this is not needed anymore in fwh 8.04, but give it a try. My nested xbrowse (4) work OK

Hth

Richard

PostPosted: Mon Apr 14, 2008 3:42 pm
by dutch
Dear Richard,

Now I use xHb.com (Nov 07) and FWH 8.04. It is the same.

Could you try my code? If you change XBROWSE with LISTBOX and change in .RC file with TWbrowse. You will see what it is.

Regards,
Dutch

PostPosted: Mon Apr 14, 2008 6:28 pm
by nageswaragunupudi
Mr Duch

The solution is simple. You have to use ALIAS 'MAN' or ALIAS 'SUB' compulsorily. Here is the modification to your code.
Code: Select all  Expand view
     SELECT('MAN')   // optional
     REDEFINE XBROWSE oBrw1 FIELDS MAN->COD_CODE, MAN->COD_DESC ;
             HEADERS TE('????','Code'), TE('??????','Description') ;
            FIELDSIZES 50, 180 ;
            UPDATE ;
            ID 101 ;
            ALIAS 'MAN'   // This is necessary

   oBrw1:bChange := { || ( Brow_sCode( oBrw1 , oBrw2 , .F. ), oBrw1:Refresh() ) }

    SELECT('SUB')   // Optional
     SUB->(DBseek(MAN->COD_CODE))
     REDEFINE XBROWSE oBrw2 FIELDS SUB->COD_CODE, SUB->COD_DESC ;
            HEADERS TE('????','Code'), TE('??????','Description') ;
            FIELDSIZES 50, 180 ;
            UPDATE ;
            ID 102  ;
            ALIAS 'SUB'    // This is necessary



With these modifications, the same code works the same way both on wbrowse and xbrowse.

You may like to know why the ALIAS '???' is "Necessary".
Wbrowse initializes its setup soon after the command is executed. If alias is specified it uses the alias and if no alias is specified, it uses the current work area. But it is always recommended practice to specify ALIAS even with wbrowse.

In contrast, xBrowse initializes its setup while executing oBrw:CreateFromCode() / oBrw:CreateFromResource(). In case of resources, if oBrw:CreateFromResource is not specified, it initializes while activating the dialog.

If ALIAS clause is specified with the browse definition, it uses the specified alias. If it is not specified ( as in this case) it uses the current wokarea when the dialog is activated. In this case it is 'SUB'. So the same alias is used to set up both browses.

It is always desirable to specify the workarea as ALIAS 'MAN' or ALIAS 'SUB' along with the command.

PostPosted: Mon Apr 14, 2008 6:35 pm
by nageswaragunupudi
Mr Richard Chidiak

Richard Chidiak wrote:Dutch

I had a smiliar problem with several nested xbrowse, it was fixed by adding to each browse

obrw:bBookMark := {| n | iif( n == nil,aliasxxx->(RecNo()), aliasxxx->(dbgoto(n)) ) } // Required!

In theory this is not needed anymore in fwh 8.04, but give it a try. My nested xbrowse (4) work OK

Hth

Richard


Kindly do not mistake me that I am repeating this for the second time. Bookmark assignment is really not necessary. XBrowse makes the same assignment. It is not only in 8.04. This assignment was there the same way since very long time ( from the time I started 32 bit programming).

The real reason for your problem if any must be different. Particularly please check up if you assigned the oBrw:cAlias correctly for each browse. Real solution is not this bBookMark codeblock but should be something else.

PostPosted: Tue Apr 15, 2008 1:10 am
by dutch
Dear nageswaragunupudi,

Thanks a lot, it works as expectation.

Thank for your help and give me an idea of it.

Regards,
Dutch
nageswaragunupudi wrote:Mr Duch

The solution is simple. You have to use ALIAS 'MAN' or ALIAS 'SUB' compulsorily. Here is the modification to your code.

With these modifications, the same code works the same way both on wbrowse and xbrowse.

You may like to know why the ALIAS '???' is "Necessary".
Wbrowse initializes its setup soon after the command is executed. If alias is specified it uses the alias and if no alias is specified, it uses the current work area. But it is always recommended practice to specify ALIAS even with wbrowse.

In contrast, xBrowse initializes its setup while executing oBrw:CreateFromCode() / oBrw:CreateFromResource(). In case of resources, if oBrw:CreateFromResource is not specified, it initializes while activating the dialog.

If ALIAS clause is specified with the browse definition, it uses the specified alias. If it is not specified ( as in this case) it uses the current wokarea when the dialog is activated. In this case it is 'SUB'. So the same alias is used to set up both browses.

It is always desirable to specify the workarea as ALIAS 'MAN' or ALIAS 'SUB' along with the command.