A sample for building CDX-Files w. Syntax-Check

A sample for building CDX-Files w. Syntax-Check

Postby ukoenig » Tue Feb 12, 2008 6:16 pm

#include "FiveWin.ch"

// Your SOFTWARE.exe
c_dir := GetModuleFilename(GetInstance(),"SOFTWARE.EXE" + ;
CHR(0), 255)
c_pfad := left ( c_dir, rat( "\", c_dir) -1 )

REQUEST DBFCDX
RDDSETDEFAULT( "DBFCDX" )

DBFARRAY := {}
// FIELDS DBCREATE("PRODUKT"
// --------------------------------------------
AADD(DBFARRAY, { "PRODUKT", "C", 60, 0 })
AADD(DBFARRAY, { "LEISTART", "C", 1, 0 })
AADD(DBFARRAY, { "LEISTNR", "N", 2, 0 })

DBCREATE("&c_pfad\PRODUKT.DBF", DBFARRAY, "DBFCDX", .t. )
CLOSE DATABASE

// Delete Old Index
// ----------------------
DELETE FILE "&c_pfad\PRODUKT.CDX" // Indexname = DBFname,
// Two Index-Files in One ( Compound )

// INDEX SAMPLES :
// ------------------------
// ORDCREATE( ,"PRODUKT","LOWER(produkt)", ;
// {|| LOWER(produkt) } , .T. ) // UNIQUE ( .T. )
//
// Needed together
// ---------------------
// ORDCONDSET( , , , , , , , , , , .T. ) // DOWN-index
// ORDCREATE( ,"PRODUKT","STR(leistnr)", ;
// {|| STR(leistnr) } , .F. )
//
// Has to be LOWER !! because of seek => ÄÖÜ
// Use your Network-Function !!
// ----------------------------------------
if NET_USE(c_pfad + "\PRODUKT.DBF",3,5,.f.)
// Creates a Compound-Index when => ORDCREATE( ,"........

// The Index will be open together with the DBF

ORDCREATE( ,"PROD1","LOWER(leistart) + str(leistnr) ;
+ str(produkt_nr)", ;
{|| LOWER(leistart) + str(leistnr) + ;
str(produkt_nr) } , .F. )

// Extra CDX-File
// ORDCREATE( "PRODUKT1" ,"PROD1","LOWER(leistart) + ;
str(leistnr) + str(produkt_nr)", ;
// {|| LOWER(leistart) + str(leistnr) + str(produkt_nr) } , .F. )

ORDCREATE( ,"PROD2","LOWER(produkt)", ;
{|| LOWER(produkt) } , .F. )
endif

// Selects Index-Information
//----------------------------------
TERMARRAY := {}
// Contents of the Compound-Index
// -------------------------------------------
AADD(TERMARRAY, ;
{ LTRIM(STR(ORDNUMBER("PROD1"))), ;
ORDBAGNAME(1), ORDNAME(1), ORDKEY(1), ;
IIF(ORDISUNIQUE(1), "UNIQUE"," "), ORDFOR(1), ;
IIF( ORDDESCEND(1,ORDBAGNAME(1)), "DOWN", "UP") } )

AADD(TERMARRAY, ;
{ LTRIM(STR(ORDNUMBER("PROD2"))), ;
ORDBAGNAME(2), ORDNAME(2), ORDKEY(2), ;
IIF(ORDISUNIQUE(2), "UNIQUE"," "), ORDFOR(2), ;
IIF( ORDDESCEND(2,ORDBAGNAME(2)), "DOWN", "UP") } )

SHOW_CDX()

RETURN( NIL )

//------ For Control ==> Is shown only, when the index is OK -----

FUNCTION SHOW_CDX()
local oDlg10, oBrw

DEFINE DIALOG oDlg10 FROM 2, 2 TO 20, 105 TITLE "Infos about FOXPRO-CDX-Index"

@ 0.5, 0.5 LISTBOX oBrw ;
FIELDS "", "", "", "", "", "", "" ;
HEADERS "Order", "Prim.-Index", "Sec.-Index", "Expression", "Equal", "Filter", "Up / Down" ;
FIELDSIZES 40, 70 , 70, 300, 52, 190, 60 ;
OF oDlg10 SIZE 400, 100

oBrw:nAt = 1
// use more Array-elements if needed.
// ----------------------------------------------
oBrw:bLine = { || { TERMARRAY[ oBrw:nAt ][ 1 ], ;
TERMARRAY[ oBrw:nAt ][ 2 ], ;
TERMARRAY[ oBrw:nAt ][ 3 ], ;
TERMARRAY[ oBrw:nAt ][ 4 ], ;
TERMARRAY[ oBrw:nAt ][ 5 ], ;
TERMARRAY[ oBrw:nAt ][ 6 ], ;
TERMARRAY[ oBrw:nAt ][ 7 ] } }

oBrw:bGoTop = { || oBrw:nAt := 1 }
oBrw:bGoBottom = { || oBrw:nAt := Eval( oBrw:bLogicLen ) }
oBrw:bSkip = { | nWant, nOld | nOld := oBrw:nAt, ;
oBrw:nAt += nWant,;
oBrw:nAt := Max( 1, Min( oBrw:nAt, Eval( oBrw:bLogicLen ) ) ),;
oBrw:nAt - nOld }
oBrw:bLogicLen = { || Len( TERMARRAY ) }
oBrw:cAlias = "Array" // Just put something

// Vert / Hor
@ 6.3, 25 BUTTON "&Exit" OF oDlg10 SIZE 80, 18 ;
ACTION ( oDlg10:End() )

ACTIVATE DIALOG oDlg10 CENTERED

RETURN( NIL )
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 58 guests