Page 1 of 1

Browsing arrays

PostPosted: Tue Nov 07, 2006 12:36 am
by Gilbert
Hi all,

I have a situation where I need to browse an array. The problem is that it can be a one or two dimension array. At the time the array is passed to my function I still don`t know what type of array the function will have to browse and how many columns it includes.

So I want the function to determine this by itself and display all the elements and columns. So far I partly solved the problem execpt for oLbx:bLine where I have no idea of how I can display all columns.

Any ideas

Regards, :!:

PostPosted: Fri Nov 10, 2006 5:49 pm
by Detlef Hoefner
Gilbert,

as far as i know you can not browse one dimensional arrays.
At least not with TWBrowse and TSBrowse.

One dimension you can list in a normal listbox.

Regards,
Detlef

PostPosted: Mon Nov 13, 2006 7:50 pm
by Gilbert
Hi Detlef,

Sorry to tell you that I have browse array with TWBrowse without any problems in many of my applications so far.

That is not my problem. My real problem is that in the application under developpement I need to browse a 2 dimensions array not knowing how many column I will need. If the array was a fixed structure that would be no problem, but it the lenght of the second dimension change depending on what the user does.

Since all the columns must be predefine when calling TWBrowse I cannot use a loop to create the needed columns. That is my problem.


Regards,

PostPosted: Mon Nov 13, 2006 11:21 pm
by Detlef Hoefner
Gilbert,

if you need a variable number of columns try this:

Code: Select all  Expand view
   DEFINE DIALOG oDlg NAME "STATBROWSE" ;
          TITLE OemToAnsi( cTitle );
          of oWnd

   REDEFINE COLUMN BROWSE oBrow ID 40 OF oDlg

   oBrow:SetArray( gaStatArr )
   oBrow:nFreeze := 1


   ADD COLUMN TO oBrow ARRAY ELEM 1;
      HEADER  aHeader[1];
      SIZE    aSize[1];
      PICTURE aPict[1];
      NOBAR;
      LEFT

   for n := 2 to len( aHeader )
      oBrow:AddColumn( TCColumn():New(;
            OemToAnsi( aHeader[ n ] ), MakeBlock( n, oBrow ),;
            aPict[ n ],,, If( !.T., "LEFT", Upper( "RIGHT" ) ), aSize[ n ], .F., .F.,,,, .F. ) )
   next

   ADD COLUMN TO oBrow ;// ARRAY ELEM 1;
      HEADER  " ";
      SIZE    16;
      PICTURE NIL;
      NOBAR;
      LEFT
...
...
...

//////////////////////////////////
STATIC FUNCTION MakeBlock(n, oBrw)
//////////////////////////////////
RETURN ( {|x| if(pcount() > 0, oBrw:aArray[oBrw:nAt][n] := x, oBrw:aArray[oBrw:nAt][n])} )


This is sample when i use TSBrowse.
Maybe this could help you?

Best regards,
Detlef

PostPosted: Wed Nov 15, 2006 2:23 am
by Gilbert
Hi Biel,


At first look it seem like that`s what I was looking for. I will get on it this coming weekend.

Thanks

Gilbert