Page 1 of 1

xBrowse one dimensional array

Posted: Mon Jun 23, 2008 3:21 pm
by Otto
Does xBrowse work on a one dimensional array.

Regards,
Otto

Posted: Mon Jun 23, 2008 3:42 pm
by nageswaragunupudi
No :(
Wish it works. Right ?

Posted: Mon Jun 23, 2008 4:20 pm
by Otto
Hello NageswaraRao,

Thank you.
I tested the printer code from Richard and wanted to show the result in a Xbrowse.

http://forums.fivetechsoft.com/viewtopic.php?t=11640

But it didn’t work. I added a extra field and then all was ok.
Regards,
Otto

Posted: Mon Jun 23, 2008 5:03 pm
by nageswaragunupudi
Mr Otto

I am extremely sorry for my hasty comment. Single dimentional arrays can be browsed like this.


Code: Select all | Expand

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

function Main()

   local oWnd, oBrw
   local aList := { "One..", "Two..", "Three", "Four.", "Five." }

   DEFINE WINDOW oWnd

   @ 0,0 XBROWSE oBrw ARRAY aList OF oWnd

   ADD TO oBrw DATA oBrw:aRow HEADER 'Item'

   oBrw:CreateFromCode()
   oWnd:oClient := oBrw

   ACTIVATE WINDOW oWnd

return nil

/*
   otherways of writing the above code.

   ADD TO oBrw DATA aList[ oBrw:nArrayAt ] HEADER "item"

   or

   oCol := oBrw:AddCol()
   oCol:bStrData := { || aList[ oBrw:nArrayAt ] }

   But I prefer to write the shortest code as above. XBrowse pampers my laziness.

*/



Posted: Mon Jun 23, 2008 6:30 pm
by Otto
Hello NageswaraRao,

thank you for your help.

The dBase syntax is working perfectly but trying the other two ways you suggested I get an error.
ADDCOL no method ( I am not sure but I think I am still on FW 8.02)

And the first test errors out with argument error Len from errorsys, line 0.

Would you please be so kind to help me.
Thanks in advance
Otto



STATIC FUNCTION ShowPrinters( oWnd )
local oChild, oBrw, oCol
local ADEVICES := {}
local aStruc:={}

ADEVICES := GETIMPRI(ADEVICES)

DEFINE WINDOW oChild TITLE "DBF structrure without record selector" MDICHILD OF oWnd

oBrw := TXBrowse():New( oChild )
oBrw:SetArray( ADEVICES)
ADD TO oBrw DATA ADEVICES[ oBrw:nArrayAt ] HEADER "item"

// oCol := oBrw:AddCol()
// oCol:bStrData := { || ADEVICES[ oBrw:nArrayAt ] }

// @ 0,0 XBROWSE oBrw ARRAY ADEVICES OF oChild
// ADD TO oBrw DATA oBrw:aRow HEADER 'Item'


oBrw:CreateFromCode()
oChild:oClient := oBrw

ACTIVATE WINDOW oChild ON INIT oBrw:SetFocus()

RETURN NIL

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


FUNCTION GETIMPRI(ADEVICES)
*----------------------------------------
LOCAl cAllEntries, cEntry, I, cName, cPrn, cPort, J

cAllEntries := STRTRAN( GetProfString( "Devices" ), Chr( 0 ), CRLF )
FOR I:= 1 TO MlCount( cAllEntries )
cName := MemoLine( cAllEntries,,I)
cEntry := GetProfString( "Devices",cName,"")
J := 2
WHILE ! EMPTY(cPort := StrToken(cEntry,J++,","))
// AADD(aDevices,TRIM(cName))
AADD(aDevices,TRIM(cName) + "," + CENTRY ) // CHIDIAK
ENDDO
NEXT
RETURN aDevices

Posted: Tue Jun 24, 2008 9:55 am
by nageswaragunupudi
Mr Otto

>
oCol := oBrw:AddCol()
oCol:bStrData := { || ADEVICES[ oBrw:nArrayAt ] }
>

This syntax should work even with the oldest version of XBrowse. I can't think of any reason why it should not work for you. Will you please try again ?

I personally suggest you to use the latest version 8.05. Do you have any techinical problems in upgrading to 8.05 ?

Posted: Sat Jun 28, 2008 1:54 pm
by nageswaragunupudi
Mr Otto

I checked up the source code of xbrowse in 8.02.
If you are using this version, please make the following change in the orginal XBrowse.Prg

Code: Select all | Expand

METHOD SetArray( ........... )

<< FWH code >>


   ::aCols := {}    // after this is FWH code
 
   if ValType( aData[ 1 ] ) == 'A'   // insert this line here

   // fwh code  continues
   for nFor := 1 to len( aData[ 1 ] )
      oCol := ::AddCol()
     
      << FWH code >>

   next
  // after this FWH code,
   endif // insert this line here
  << fwh code continues >>


After making this change, you can now use it for single dimentional array.

Code: Select all | Expand

oBrw  := TXBrowse():New( oChild )
oBrw:SetArray( ADEVICES )
oCol := oBrw:AddCol()
oCol:bStrData := { || ADEVICES[ oBrw:nArrayAt ] }


Hope this works for you, if you are using version 8.02

Posted: Sun Jun 29, 2008 4:28 am
by Otto
Thank you very much for your help.
Regards,
Otto

Posted: Sun Jul 06, 2008 8:49 pm
by Antonio Linares
FWH 8.06 handles single dimensional arrays ( even with mixed type values ) easily:

Example

Code: Select all | Expand

#include 'fivewin.ch'
#include 'xbrowse.ch'

function main()

   local oDlg, oBrw
   local aData := { 'one  ', 'two  ', 'three', 20, DATE() }

   DEFINE DIALOG oDlg SIZE 200,200 PIXEL

   oBrw  := TXBrowse():New( oDlg )
   oBrw:SetArray( aData )
   oBrw:aCols[ 1 ]:nWidth  := 50
   oBrw:aCols[ 1 ]:cHeader := 'Array'

   oBrw:nStretchCol  := 1
   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED

return nil