xBrowse one dimensional array

Post Reply
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

xBrowse one dimensional array

Post by Otto »

Does xBrowse work on a one dimensional array.

Regards,
Otto
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

No :(
Wish it works. Right ?
Regards

G. N. Rao.
Hyderabad, India
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Mr Otto

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

Code: Select all

#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.

*/


Regards

G. N. Rao.
Hyderabad, India
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post 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 ?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post 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

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

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
Regards

G. N. Rao.
Hyderabad, India
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Thank you very much for your help.
Regards,
Otto
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

FWH 8.06 handles single dimensional arrays ( even with mixed type values ) easily:

Example

Code: Select all

#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply