Page 1 of 1

oBrw:SetArray(), differences beetween TCBrwose and XBrowse

Posted: Thu Apr 03, 2008 4:06 pm
by Marco Turco
Hi,
I am testing XBrowse to evaluate a migration from the standard TcBrowse FWH class.

The first (and most important difference - and problem -) I found is this:

if I make an array browse and I need to add another element I already added it nto the array to do then a symply oBrw:SetArray(aUpdatedArray).

There are no problem to do this with TCBrowse but XBrowse delete all the header and size informations.

I'm using the November 2007 Xbrowse class,
is this changed with this lastest xBrowse's updates or is there any turn-around ?

Thanks.

This is a sample code that show the problem:

#include "FiveWin.ch"
#include "tcbrowse.ch"

static oWnd
static oBrw,aArray

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

function Main()


DEFINE WINDOW oWnd TITLE "Testing Keys";
MENU BuildMenu();
MDI


ACTIVATE WINDOW oWnd

return nil

Function Test()
aArray:={}
aadd(aArray,{1,"Henry"})


oBrw := TXBrowse():New( oWnd:oWndClient )
oBrw:SetArray( aArray)

oBrw:aCols[1]:cHeader := "Num"
oBrw:aCols[2]:cHeader := "Name"

oBrw:lRecordSelector := .f.
oBrw:nLastEditCol:=3
oBrw:nFreeze:=1
oBrw:CreateFromCode()

oBrw:Move(5,5,200,200)


@ 14, 4 BUTTON "&Add row" SIZE 100,80 OF OWND:oWndClient;
ACTION AddRow()


return nil


function BuildMenu()

local oMenu
local cAction

MENU oMenu
MENUITEM "TEST";
ACTION TEST()
ENDMENU

RETURN(OMENU)

Function AddRow()

aadd(aArray,{len(aArray)+1,"Henry"})
oBrw:SetArray(aArray)
oBrw:Refresh()
return

Ad a Array-element at runtime to xBrowse

Posted: Thu Apr 03, 2008 6:24 pm
by ukoenig
Hello Marco,

I'm just busy, to create a tool for xbrowse.
As i have seen your message, i added a function
for a array test.
There was no problem to add a element at runtime.
I try, to send you a sample today.

Regards

Uwe

Posted: Thu Apr 03, 2008 6:31 pm
by Marco Turco
Thanks Uwe,
however my problem is not to add or change an element at runtime but the SetArray method that called at runtime to update the displayed array it delete the header and the others initial settings.

Posted: Thu Apr 03, 2008 6:45 pm
by Otto
Marco, I had the same problem:

http://fivetechsoft.com/forums/viewtopi ... ight=array
Regards,
Otto

Arrays in xbrowse at runtime

Posted: Thu Apr 03, 2008 8:29 pm
by ukoenig
Hello

Here is just a sample

Code: Select all


...
...

Local oDlg, oLbx1, oBtn1, aFont

oFont1 := TFont():New("Arial", ,-12,.F.,.T. , , , ,.F.)

// The Array 9 Rows and 5 Cols
// ----------------------------------------
PRIVAT aTEST[9][5]

aTEST[1] := { " 1", "Test1", "Test1", "Test1", "Test1" }
aTEST[2] := { " 2", "Test2", "Test2", "Test2", "Test2" }
aTEST[3] := { " 3", "Test3", "Test3", "Test3", "Test3" }
aTEST[4] := { " 4", "Test4", "Test4", "Test4", "Test4" }
aTEST[5] := { " 5", "Test5", "Test5", "Test5", "Test5" }
aTEST[6] := { " 6", "Test6", "Test6", "Test6", "Test6" }
aTEST[7] := { " 7", "Test7", "Test7", "Test7", "Test7" }
aTEST[8] := { " 8", "Test8", "Test8", "Test8", "Test8" }
aTEST[9] := { " 9", "Test9", "Test9", "Test9", "Test9" }

// xBrowse
// COLOR1 and COLOR2 are two Colors for different Row-colors
// ----------------------------------------------------------------------------------
oLbx1 := TXBrowse():New( oDlg )
oLbx1:nMarqueeStyle := MARQSTYLE_HIGHLROW
oLbx1:nColDividerStyle	 := LINESTYLE_BLACK
oLbx1:nRowDividerStyle := LINESTYLE_BLACK
oLbx1:SetArray( aTEST )
oLbx1:lVScroll := .T.
oLbx1:lHScroll := .F.
oLbx1:lFooter := .T.
// Define alternating row colors 
// -------------------------------------
oLbx1:bClrStd := {|| IF ( EVAL ( oLbx1:bKeyno, NIL, oLbx1 ) %2 == 0, ;
{ CLR_BLACK, COLOR1 }, { CLR_BLACK, COLOR2 } ) }
 for nFor := 1 to Fcount()
      oLbx1:aCols[ nFor ]:cHeader := Padr("Font 1", 11)
      oLbx1:aCols[ nFor ]:oDataFont = oFont1
next

// From Resource ID-no 110
// -----------------------------------
oLbx1:CreateFromResource( 110 )

// Start No
// ----------
nNO := 9

// Send a new Array-element to oLbx1 with a button
// ---------------------------------------------------------
REDEFINE BUTTONBMP oBtn1  ID 270 OF oDlg1 ;
ACTION ( nNO++, cTest := "Test" + LTRIM( str(nNO) ), ;
                AADD( aTEST,  { LTRIM( STR(nNO) ), cTest, cTest, cTest, cTest } ), ;
                oLbx1:Gobottom(), oLbx1:Refresh() ) ;
BITMAP "color_5" PROMPT " &Add Array" TEXTRIGHT
oBtn:cToolTip = { "Add 1 Array-Element to Browser 1", ;
                             "Add Array", 1, CLR_BLACK, 14089979 } 

In the xbrowse-tool, EVERYTHING !!! has to work at runtime.
Many things i had to do, are complete different to normal
programming.
I think. maybe at weekend, you can have a look at the xBrowse-tool.
It is a extra applicatiĆ³n now.
It is complete new done with folders, to try different things
like color-, font, style-changes and much more.


Regards

Uwe :lol:

Posted: Fri Apr 04, 2008 5:33 am
by nageswaragunupudi
There have been lots of improvements in array browses in Xbrowse.

Simplest way is
@ 0,0 XBROWSE oBrw OF oWnd ARRAY aData [AUTOCOLS] [AUTOSORT]

AUTOCOLS adds all columns. AUTOSORT sets sort on columns.

If we want to add only selected columns, but not all columns :

@ 0,0 XBROWSE oBrw COLUMNS 5,4,3 HEADERS "Five","Four","Three" OF oWnd

The data can be any data type and we need not even convert them to character values.

After setting up the browse we can add any more columns either by command

ADD TO oBrw ARRAY ELEMENT 8 PICTURE "9999" HEADER "Eight"

[or ]

oCol := oBrw:AddCol()
oCol:nArrayCol := 8 // no need to define complex codeblocks
oCol:cEditPicture := "99999"
oCol:cHeader := "Eight"

The new command syntax enables reducing long complex coding to just a few lines. Also the command syntax is very similar to the well known LISTBOX syntax and TCColumn browse syntax making migration very fast and easy

Posted: Fri Apr 04, 2008 7:36 am
by Marco Turco
Yes, solved.
I only have to make an oBrw:Refresh() without a new SetArray to display the changes.

Thanks to all.

Posted: Fri Apr 04, 2008 7:38 am
by nageswaragunupudi
Marco Turco wrote:Yes, solved.
I only have to make an oBrw:Refresh() without a new SetArray to display the changes.

Thanks to all.
Yes. SetArray should not be used again at any stage even in earlier versions of XBrowse