Some changes in xBrowse, to read, edit a. write OemToAnsi

Some changes in xBrowse, to read, edit a. write OemToAnsi

Postby ukoenig » Mon Jan 28, 2008 8:12 pm

Hello from Germany

With all extern Browsers i know, DBAdmin, DBView and so on
it is possible to switch between ANSI and OEM

With some small changes in the xBrowse-Class you can do the same.
It is possible, to read, edit und write in OemToAnsi-Style.
with xBrowse

Sample :

oBrw5 := TXBrowse():New( oDlg3 )
oBrw5:nMarqueeStyle := MARQSTYLE_HIGHLCELL
oBrw5:nColDividerStyle := LINESTYLE_BLACK
oBrw5:nRowDividerStyle := LINESTYLE_BLACK
oBrw5:lColDividerComplete := .t.
oBrw5:nHeaderLines := 1
oBrw5:nDataLines := 1
oBrw5:lAllowColSwapping := .t.
// ----------------------------------------------
// ---------------------- NEW -----------------------
oBrw5:lOemToAnsi := lOemAnsi // Var for Oem / Ansi .T. or .F.
// ---------------------------------------------
// ---------------------------------------------
oBrw5:SetRDD()

define a Var lOemAnsi := .T. if Ansi, .or. .F. if Oem you want to use.
before you open the database you set the var.
The database is shown with the mode you defined in lOemAnsi.

// Celledit
// ---------
for nFor := 1 to len( oBrw5:aCols )
oCol := oBrw5:aCols[ nFor ]
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

//----------- CHANGES in xBROWSE-Class ----------------------//

CLASS TXBrowse FROM TControl

DATA lCreated,;
lRecordSelector,;
lHScroll,;
lVScroll,;
lAllowRowSizing,;
lAllowColSwapping,;
lAllowColHiding,;
lColDividerComplete,;
;
lFastEdit, ;
;
lEditMode,;
lRefreshOnlyData,;
l2007, ;
// ------------- ADD this line ------------------
lOemToAnsi ; // OemToAnsi look !!!!
// -------------------------------
AS LOGICAL

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

METHOD New( oWnd ) CLASS TXBrowse

DEFAULT oWnd := GetWndDefault()

::oWnd := oWnd

If oWnd != nil
::oFont := oWnd:oFont
Endif

::aCols := {}
::aSelected := {}

::bClrHeader := {|| { GetSysColor( COLOR_BTNTEXT ), ;
GetSysColor( COLOR_BTNFACE ) } }
::bClrFooter := ::bClrHeader
::bClrStd := {|| { CLR_BLACK, GetSysColor( COLOR_WINDOW )} }
::bClrSel := {|| { CLR_BLACK, ;
GetSysColor( COLOR_INACTIVECAPTIONTEXT )} }
::bClrSelFocus := {|| { CLR_WHITE, ;
GetSysColor( COLOR_HIGHLIGHT )} }

// ::bKeyCount := { || 1 }
// ::bKeyNo := { || 1 }
// ::bSkip := { || 0 }
// ::bBookMark := { || 0 }

::cCaption := ""
::cAlias := ""
::cSeek := ""

::nDataType := DATATYPE_RDD

::nTop := 0
::nLeft := 0
::nBottom := 100
::nRight := 100

::nStyle := nOr( WS_CHILD, WS_BORDER, ;
WS_VISIBLE, WS_TABSTOP )

::SetColor( CLR_BLACK, GetSysColor( COLOR_WINDOW ) )

::lDrag := .f.
::lFocused := .f.
::lHScroll := .t.
::lVScroll := .t.

::lRecordSelector := .t.
::lAllowRowSizing := .t.
::lColDividerComplete := .f.
::lAllowColSwapping := .t.
::lAllowColHiding := .t.
::lFastEdit := .f.

::nRowSel := 1
::nColSel := 1
::nColOffset := 1
::nFreeze := 0
::nCaptured := 0
::nLastEditCol := 0

::nRowDividerStyle := LINESTYLE_NOLINES
::nColDividerStyle := LINESTYLE_NOLINES
::nMarqueeStyle := MARQSTYLE_SOLIDCELL

::nHeaderLines := 1
::nFooterLines := 1
::nDataLines := 1

::hBmpRecSel := FwRArrow()

::lHeader := .t.
::lFooter := .f.
::lRefreshOnlyData := .f.

::l2007 = .T.
// -------------------- NEW -Add this line -----
::lOemToAnsi = .F.
// ------------------------------------------------

return Self

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

METHOD SetRDD( lAddColumns ) CLASS TXBrowse

local oCol
local cAlias, cAdsKeyNo, cAdsKeyCount
local nFields, nFor

DEFAULT lAddColumns := .T.

if Empty( ::cAlias )
::cAlias := Alias()
if Empty( ::cAlias )
return nil
endif
endif

cAlias := ::cAlias

DEFAULT ::bGoTop := {|| ( cAlias )->( DbGoTop() ) },;
::bGoBottom := {|| ( cAlias )->( DbGoBottom() ) },;
::bSkip := {| n | iif( n == nil, n := 1, ), ;
( cAlias )->( DbSkipper( n ) ) },;
::bBof := {|| ( cAlias )->( Bof() ) },;
::bEof := {|| ( cAlias )->( Eof() ) },;
::bBookMark := {| n | iif( n == nil,;
( cAlias )->( RecNo() ),;
( cAlias )->( DbGoto( n );
) ) }

If "ADS"$( ::cAlias )->( RddName() )
cAdsKeyNo := "{| n, Self | iif( n == nil, " +;
"Round( " + cAlias + ;
"->( ADSGetRelKeyPos() ) * Self:nLen, 0 ), "+;
cAlias + "->( ADSSetRelKeyPos( n / Self:nLen ) ) ) }"

cAdsKeyCount := "{|| " + cAlias + "->( ADSKeyCount(,,1) )}"

DEFAULT ::bKeyNo := &cAdsKeyNo ,;
::bKeyCount := &cAdsKeyCount
else
DEFAULT ::bKeyNo := {| n | iif( n == nil,;
( cAlias )->( OrdKeyNo() ),;
( cAlias )->( OrdKeyGoto( n );
) ) },;
::bKeyCount := {|| ( cAlias )->( OrdKeyCount() ) }
Endif

if lAddColumns
if len( ::aCols ) == 0
nFields := ( cAlias )->( FCount() )
for nFor := 1 to nFields
oCol := ::AddCol()
oCol:cHeader := ( cAlias )->( FieldName( nFor ) )
// -------------------------------------------------------
// ---- NEW ---------------------------------------------------
IF ::lOemToAnsi = .F.
oCol:bStrData := GenFieldBlock1( cAlias, nFor )
ELSE
oCol:bStrData := GenFieldBlock2( cAlias, nFor )
ENDIF
// --------------------------------------------------------
// --------------------------------------------------------
next
endif
endif

return nil

//----------------- Oem ----------------------------------//

STATIC FUNCTION GenFieldBlock1( cAlias, nField )

RETURN {|| cValToChar( ( cAlias )->( FieldGet( nField ) ) ) }

//------------------ Ansi ---------------------------------//

STATIC FUNCTION GenFieldBlock2( cAlias, nField )

RETURN {|| cValToChar( OemToAnsi( ( cAlias )->( FieldGet( nField ) ) ) ) }

It works for me but i think, there are maybe still more changes
to do. I stopped at this point.

Regards
Uwe König :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: wilsongamboa and 42 guests