#include "fivewin.ch"
//----------------------------------------------------------------------------//
function Main()
UseXBrowseFilter()
UseSplitArrays()
return nil
//----------------------------------------------------------------------------//
static function UseXBrowseFilter()
local aParent, aChild
local oDlg, oFont, oParent, oChild
USE STATES
aParent := FW_DbfToArray( "CODE,NAME" )
CLOSE STATES
USE CUSTOMER
aChild := FW_DbfToArray( "STATE,FIRST,CITY,SALARY" )
CLOSE CUSTOMER
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
DEFINE DIALOG oDlg SIZE 700,400 PIXEL TRUEPIXEL FONT oFont ;
TITLE "XBROWSE ARRAY FILTERING CAPABILITIES"
@ 20,20 XBROWSE oParent SIZE 200,-20 PIXEL OF oDlg ;
DATASOURCE aParent AUTOCOLS HEADERS "Code", "State" ;
CELL LINES NOBORDER
WITH OBJECT oParent
:SetGroupHeader( "STATES" )
:bChange := { || oChild:Seek( "" ), oChild:Seek( oParent:Code:Value ) } // Not necessary but desirable to use
//
:CreateFromCode()
END
@ 20,220 XBROWSE oChild SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE aChild AUTOCOLS ;
HEADERS "St", "FirstName", "City", "Salary" ;
AUTOSORT ;
COLSIZES 60,120,130 ;
CELL LINES NOBORDER
WITH OBJECT oChild
:SetGroupHeader( "CUSTOMERS" )
:lIncrFilter := .t.
:bFilterExp := { |cSeek,aRow| aRow[ 1 ] = cSeek }
:bKeyChar := { |k| If( k == VK_BACK .or. k > 31, 0, nil ) }
//
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED ON INIT oChild:Seek( aParent[ 1, 1 ] )
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
static function UseSplitArrays()
local aParent, aChild, n, nAt
local oDlg, oFont, oParent, oChild
USE STATES
aParent := FW_DbfToArray( "CODE,NAME,ARRAY(0)" )
CLOSE STATES
USE CUSTOMER
aChild := FW_DbfToArray( "STATE,FIRST,CITY,SALARY" )
CLOSE CUSTOMER
for n := 1 to Len( aChild )
nAt := AScan( aParent, { |a| a[ 1 ] == aChild[ n, 1 ] } )
if nAt > 0
AAdd( aParent[ nAt, 3 ], aChild[ n ] )
endif
next
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
DEFINE DIALOG oDlg SIZE 700,400 PIXEL TRUEPIXEL FONT oFont ;
TITLE "USING SPLIT ARRAYS"
@ 20,20 XBROWSE oParent SIZE 200,-20 PIXEL OF oDlg ;
DATASOURCE aParent AUTOCOLS HEADERS "Code", "State" ;
CELL LINES NOBORDER
WITH OBJECT oParent
:SetGroupHeader( "STATES" )
:bChange := { || oChild:aArrayData := oParent:aRow[ 3 ], ;
oChild:Refresh( .t. ) }
//
:CreateFromCode()
END
@ 20,220 XBROWSE oChild SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE aParent[ 1, 3 ] AUTOCOLS ;
HEADERS "St", "FirstName", "City", "Salary" ;
AUTOSORT ;
COLSIZES 60,120,130 ;
CELL LINES NOBORDER
WITH OBJECT oChild
:SetGroupHeader( "CUSTOMERS" )
//
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
:lIncrFilter := .t.
:bChange := { || oChild:Seek( "" ), oChild:Seek( oParent:Code:Value ) }
James Bott wrote:Frances,
There is a database class you can use with arrays--perhaps it supports filters or relations.
It was a fairly recent discussion in this section. Search for it.
James
TimStone wrote:A very simple approach is to have a function that loads the secondary array. On the first browse, with ON CHANGE have it re-load the second array with values from the database. I use this method ( and have for years ) and it is actually quite fast. In one example, I have a service history. Array 1 shows the invoices. The highlighted invoice has it's details loaded into an array 2. Change 1, and 2 is instantly loaded. It actually goes a step further. Click on a line in array 2 and full detail is shown in a pop up. I've never had a complaint about speed, even across a network.
Tim
oParent:bChange := { || oChild:Seek( "" ), oChild:Seek( oParent:Code:Value ) }
...
oChild:lIncrFilter := .t.
oChild:bFilterExp := { |cSeek,aRow| aRow[ 1 ] = cSeek }
...
nageswaragunupudi wrote:aNew := AClone( oBrw:aArrayData )
ASize( aNew, oBrw:nLen )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: anserkk, Google [Bot], nageswaragunupudi and 41 guests