Page 1 of 1

Problem with xBrowse in MDI-Childs

Posted: Tue Jan 29, 2008 8:20 pm
by ukoenig
I wanted to change a Browse from Dialog to a MDI-Child
Following happens :

//------------ Quick- Browse Outlook2003 ---------------------------

FUNCTION PROG_4(oWnd,oDlg,aCtrl,nPage,oOutL2003)
local oDlg3, oFile1, cFile1 := "", oBtn1, oBtn2, obtn3, oBtn4, oBrw5, DBFTYP := ""
local oFilter, cFilter := SPACE( 70 ), cFELD := "", l_INDEX := .F.
local oSUCH, cSUCH := "", aSCOPE, nSCOPE := 1
local oEXPORT, cEXPORT := "EXPORT.DBF ", oINDKEY, cINDKEY := ""
local oOemAnsi, cOemAnsi := ""

DEFINE DIALOG aCtrl[nPage] RESOURCE "BROWSER" OF oDlg PIXEL

cFile1 := GET_DBF2() // the selected Database
DBFTYP := CabDbf (cFile1) // DBF-Header-Info CDX or NTX
IF lOemAnsi = .T. // wants to open a Oem or Ansi - Database
cOemAnsi := "ANSI"
ELSE
cOemAnsi := "OEM"
ENDIF

IF DBFTYP = "CDX"
RDDSETDEFAULT( "DBFCDX" )
ELSE
RDDSETDEFAULT( "DBFNTX" )
ENDIF

// -------- Open the Database ---------------------------------

DBSELECTAREA(1)
USE &cFile1
DBGOTOP()

BROWSE() // Database is open and shows the Data

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

// Dosn't work in a MDI-Child
// as a ARRAY and in a Dialog it is OK

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

oBrw5 := TXBrowse():New( aCtrl[nPage] )
// => aCtrl[nPage] is a MDI-Child of Outlook2003

oBrw5:nMarqueeStyle := MARQSTYLE_HIGHLCELL
oBrw5:nColDividerStyle := LINESTYLE_BLACK
oBrw5:nRowDividerStyle := LINESTYLE_BLACK
oBrw5:lColDividerComplete := .t.
oBrw5:nHeaderLines := 1
oBrw5:nDataLines := 1
oBrw5:lAllowColSwapping := .t.
oBrw5:lOemToAnsi := lOemAnsi // New OemToAnsi
oBrw5:SetRDD()

lClrFlag:=.f.
for nFor := 1 to len( oBrw5:aCols )

// Error-Message
// NO WORKAREA in USE !!!!
// as a ARRAYS it is OK
// ------------------------------------

oCol := oBrw5:aCols[ nFor ]
oBrw5:bSkip:={| nRecs | ( if(nRecs == nil, nRecs := 1,),nRecs:= ;
(1)->(dbskipper( nRecs )), ;
lClrFlag:= if( nRecs % 2 = 0, lClrFlag,!lClrFlag), nRecs) }
// Define alternating row colors
oBrw5:bClrStd:= {|| if(lClrFlag,{ CLR_BLACK, COLOR_LIGHT }, ;
{ CLR_BLACK, COLOR_DARK }) }
oCol:nEditType := 1
oCol:bOnPostEdit := {|o, v, n| IIF( n != VK_ESCAPE, ;
( IIF( Net_Lock(), ;
IIF( lOemAnsi = .T., ;
FieldPut( o:nCreationOrder, AnsiToOem(v) ), ;
FieldPut( o:nCreationOrder, v ) ), Net_ULock () ), NIL ), ) }
next

oBrw5:CreateFromResource( 110 )
aCtrl[nPage]:oClient := oBrw5

ACTIVATE DIALOG aCtrl[nPage] NOWAIT ;
ON INIT ( aCtrl[nPage]:Move( aCORS [1] + 10, aCORS [2] + 230, ;
aCtrl[nPage]:nWidth, aCtrl[nPage]:nHeight, .f. ) )

CLOSE DATABASE

RETURN( NIL )

regards
U. König :lol:

Posted: Tue Jan 29, 2008 8:51 pm
by James Bott
A dialog is modal and a MDI window is non-modal. The consequence is that when in a non-modal window you can jump out and do something else which might include changing the current workarea.

When setting up a browse or with any code referencing a database you need to always use alias referencing. In your code you have not told the browse what the alias is, like this:

oBrw:cAlias := cAlias

Or, in your case:

oBrw5:cAlias := "1"

The alias referencing issue is a big reason to use database objects since they have that built-in. You still need to tell the browse the alias, but all navigation commands are automatically alias referenced.

James

Posted: Tue Jan 29, 2008 9:12 pm
by RenOmaS

Code: Select all

....
...
If !OpenDataBase() ????  //not open database
    DBSELECTAREA(1)
    USE &cFile1
Endif
   Select( 1 )
EndIf

.......
....
ACTIVATE DIALOG aCtrl[nPage] NOWAIT ;
ON INIT ( aCtrl[nPage]:Move( aCORS [1] + 10, aCORS [2] + 230, ;
aCtrl[nPage]:nWidth, aCtrl[nPage]:nHeight, .f. ) ) ;
VALID ( CloseDatabase(), .T. )


Static Function CloseDataBase()

CLOSE DATABASE 

Return Nil
;)

Posted: Wed Jan 30, 2008 9:42 pm
by James Bott

Code: Select all

Static Function CloseDataBase() 

CLOSE DATABASE 

Return Nil
Better would be:

Code: Select all

Static Function CloseDataBase() 
   local nArea:= select(1)
   CLOSE DATABASE 
   select( nArea )
Return nil 
If you were using a database object you could simply do:

...VALID (oCust:end(), .t.)

James