Error in TXBrowse when re-assigning a new array

Error in TXBrowse when re-assigning a new array

Postby ellano » Sun Sep 29, 2013 2:30 pm

When using the following code to assign a new array to TXBrowse:

Code: Select all  Expand view
sCondic:= "SELECT number, name, cSex, color, comments FROM my_DB WHERE " + ;
                     "father='" oDbf:number"' ORDER BY cSex, birth_date"
aResult := oDbf:SqlQuery( sCondic )
...
oBrwD:=TXBrowse():New(oFld:aDialogs[6])
oBrwD:SetArray( aResult )
oBrwD:cHeaders:= {"Number", "Name", "cSex", "Color", "Comment"}
IF !empty( oBrw:aArrayData ) //if we have data or else we have an error
  oBrwD:aCols[3]:nWidth    := 90
  oBrwD:aCols[5]:nWidth    := 170
  oBrwD:aCols[1]:nDataStyle:= AL_RIGHT
  oBrwD:aCols[4]:nDataStyle:= AL_RIGHT
ENDIF  
oBrwD:CreateFromResource(101)


There is an inconsistency in TXBrowse: If the original array is empty or smaller than a newer record array (when skipping through records), then TXBrowse would not change the display and will keep the original SetArray size with only one column (???) even though the SQL statement specifies 5 in this case, If you land in an empty SQL (returning an empty array) it would show you a 1 column array with the heading "Number" and the next registers (if non-empty) will only have 1 column and will show only the number field.

Further more, if you now happen to do a new query like the following one, an assign it to the same TXBrowse (for the sake of saving space in the same dialog tab):

Code: Select all  Expand view
 sCondic:="SELECT father, cSex, birth, color, grandad, nany, family, comments FROM family " + ;
           "ORDER BY cSex, birth"
  DATABASE oDbfP
  oDbfP:LOAD()
  aCondic := oDbfP:SqlQuery( sCondic )
  oBrwD:aArrayData := aCondic  //new array over old browse window
  oBrwD:cHeaders:= {"Number", "cSex", "Birth", "Color", "GD", "GM", "Family", "Comment"}


since the old browse window had only 5 columns (and in this example was not empty in the 1st place; number, name, cSex, color, and comments) the new browse will not re-dimension correctly to 8 columns and will display only 5 columns (at least correctly!). If in the 1st place you landed in an empty register and then you navigate to a non-empty one, then you will have the 2nd case, that is, several registers showing only one column ("Number" in my case).

Any explanation or solution?
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: Error in TXBrowse when re-assigning a new array

Postby nageswaragunupudi » Wed Oct 02, 2013 4:43 am

Please test this sample and use this logic
Code: Select all  Expand view
#include "FiveWin.Ch"
#include "xbrowse.ch"

REQUEST DBFCDX

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

function main()

   local aStruct, aData, oDlg, oBrw, oFont

   USE CUSTOMER NEW VIA "DBFCDX"
   aStruct     := DBSTRUCT()
   aData       := FW_DbfToArray()
   CLOSE DATA

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 800,400 PIXEL FONT oFont
   @ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE aStruct AUTOCOLS ;
      HEADERS "Name", "Type", "Len", "Dec" CELL LINES NOBORDER

   WITH OBJECT oBrw
      //
      :CreateFromCode()
   END

   @ 10,10 BUTTON "ChangeArray" SIZE 80,12 PIXEL OF oDlg ;
      ACTION ( oBrw:aCols := {}, oBrw:SetArray( aData ), ;
               oBrw:cHeaders := ArrTranspose( aStruct )[ 1 ] )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

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


First Array
Image

After changing the array
Image
Regards

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

Re: Error in TXBrowse when re-assigning a new array

Postby ellano » Thu Oct 03, 2013 12:09 pm

Thanks for your response.

It happens to be that

Code: Select all  Expand view
oBrw:aCols := {}


did the magic.

Up until now I circumvent the problem just assigning the correct number of elements into the array so that they correspond, but that generated a lot much work on me that a simple line of code.
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 93 guests