//----------------------------------------------------------------------------//
function ExpBuilder( cExp )
local oDlg, oBrw, aFields := DBStruct(), oSay1, oSay2, oSay3, oSay4
local oExp, oCombo, cFunction, aITEM1[48], aITEM2 := {}, cSyntax := SPACE( 30 )
cExp = RTrim( cExp )
DEFINE DIALOG oDlg TITLE "Expression builder" SIZE 480, 450 // TRANSPARENT
@ 0.2, 1.5 SAY oSay1 PROMPT "Expression:" SIZE 80, 11 OF oDlg
oSay1:lTransparent := .T.
@ 1.1, 1 GET oExp VAR cExp MEMO SIZE 221, 27
@ 2.8, 1.5 SAY oSay2 PROMPT "Fields" OF oDlg SIZE 40, 10
oSay2:lTransparent := .T.
@ 2.8, 5 SAY oSay3 PROMPT "Syntax : " OF oDlg SIZE 30, 10
oSay3:lTransparent := .T.
@ 2.8, 8.5 SAY oSyntax VAR cSyntax OF oDlg SIZE 120, 10
oSyntax:lTransparent := .T.
@ 3.8, 1 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES SIZE 120, 140 OF oDlg ;
HEADERS "Name", "Type", "Len", "Dec" ;
COLSIZES 95, 30, 30, 30
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW
oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
{ CLR_BLACK, RGB( 198, 255, 198 ) }, ;
{ CLR_BLACK, RGB( 232, 255, 232 ) } ) }
oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }
oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
oBrw:CreateFromCode()
oBrw:bLDblClick = { || cExp += oBrw:aRow[ 1 ], oExp:Refresh() }
@ 3.5, 23.2 SAY oSay4 PROMPT "Functions" OF oDlg SIZE 84, 11
oSay4:lTransparent := .T.
AADD( aITEM2, { "ABS()", "ABS( numeric )" } )
AADD( aITEM2, { "ALIAS()", "ALIAS()" } )
AADD( aITEM2, { "ALLTRIM()", "ALLTRIM( String )" } )
AADD( aITEM2, { "AT()", "AT( SearchStr., TargetStr. )" } )
AADD( aITEM2, { "CDOW()", "CDOW( Datefield )" } )
AADD( aITEM2, { "CHR()", "CHR( Val )" } )
AADD( aITEM2, { "CMONTH()", "CMONTH( Datefield )" } )
AADD( aITEM2, { "CTOD()", "CTOD( String )" } )
AADD( aITEM2, { "DATE()", "DATE()" } )
AADD( aITEM2, { "DAY()", "DAY( Datefield )" } )
AADD( aITEM2, { "DELETED()", "DELETED()" } )
AADD( aITEM2, { "DESCEND()", "DESCEND( String )" } )
AADD( aITEM2, { "DMY()", "DMY( Datefield )" } )
AADD( aITEM2, { "DTOC()", "DESCEND( String )" } )
AADD( aITEM2, { "DTOS()", "DESCEND( String )" } )
AADD( aITEM2, { "EMPTY()", "DESCEND( String )" } )
AADD( aITEM2, { "IF()", "IF( Logical, True Result, False Result )" } )
AADD( aITEM2, { "IIF()", "Logical, True Result, False Result )" } )
AADD( aITEM2, { "INDEXKEY()", "DESCEND( String )" } )
AADD( aITEM2, { "ISLOWER()", "ISLOWER( String )" } )
AADD( aITEM2, { "ISUPPER()", "ISUPPER( String )" } )
AADD( aITEM2, { "LEFT()", "LEFT( String, Length )" } )
AADD( aITEM2, { "LEN()", "LEN( Expression )" } )
AADD( aITEM2, { "LOWER()", "LOWER( String )" } )
AADD( aITEM2, { "MONTH()", "MONTH( Datefield )" } )
AADD( aITEM2, { "ORDER()", "DESCEND( String )" } )
AADD( aITEM2, { "ORDKEY()", "DESCEND( String )" } )
AADD( aITEM2, { "PADC()", "PADC( String, Length, Character )" } )
AADD( aITEM2, { "PADL()", "PADL( String, Length, Character )" } )
AADD( aITEM2, { "PADR()", "PADR( String, Length, Character )" } )
AADD( aITEM2, { "RAT()", "RAT( SearchStr., TargetStr. )" } )
AADD( aITEM2, { "RECCOUNT()", "RECCOUNT()" } )
AADD( aITEM2, { "RECNO()", "RECNO()" } )
AADD( aITEM2, { "RIGHT()", "DESCEND( String, Length)" } )
AADD( aITEM2, { "SELECT()", "SELECT()" } )
AADD( aITEM2, { "SOUNDEX()", "SOUNDEX( String )" } )
AADD( aITEM2, { "SPACE()", "SPACE( Length )" } )
AADD( aITEM2, { "SQRT()", "SQRT( Numeric )" } )
AADD( aITEM2, { "STOD()", "STOD( String )" } )
AADD( aITEM2, { "STR()", "STR( String, Start, Length )" } )
AADD( aITEM2, { "STRTRAN()", "STRTRAN( TargetStr., SearchStr., ReplaceStr.)" } )
AADD( aITEM2, { "STRZERO()", "STRZERO( Number, Length, Decimal )" } )
AADD( aITEM2, { "SUBSTR()", "SUBSTR( String, Start, Length )" } )
AADD( aITEM2, { "TIME()", "TIME()" } )
AADD( aITEM2, { "TRIM()", "TRIM( String )" } )
AADD( aITEM2, { "UPPER()", "UPPER( String )" } )
AADD( aITEM2, { "VAL()", "VAL( String )" } )
AADD( aITEM2, { "YEAR()", "YEAR( Datefield )" } )
I := 1
FOR I := 1 TO LEN( aITEM2 )
aITEM1[I] := aITEM2[I][1]
NEXT
@ 4.5, 17.3 COMBOBOX oCombo VAR cFunction ITEMS aITEM1 ;
OF oDlg SIZE 92, 50 ON CHANGE ( cExp += Left( cFunction, Len( cFunction ) - 1 ) + " ", ;
cSyntax := aITEM2[oCombo:nAt][2], oSyntax:Refresh(), oExp:Refresh() )
@ 6, 23.1 SAY "Operators" OF oDlg SIZE 40, 10
@ 5.8, 23 BUTTON "=" OF oDlg SIZE 15, 15 ACTION ( cExp += " = ", oExp:Refresh() )
@ 5.8, 26.2 BUTTON "<>" OF oDlg SIZE 15, 15 ACTION ( cExp += " <> ", oExp:Refresh() )
@ 5.8, 29.4 BUTTON "+" OF oDlg SIZE 15, 15 ACTION ( cExp += " + ", oExp:Refresh() )
@ 5.8, 32.6 BUTTON "(" OF oDlg SIZE 15, 15 ACTION ( cExp += " ( ", oExp:Refresh() )
@ 5.8, 35.8 BUTTON ".T." OF oDlg SIZE 15, 15 ACTION ( cExp += " .T. ", oExp:Refresh() )
@ 6.8, 23 BUTTON "<" OF oDlg SIZE 15, 15 ACTION ( cExp += " < ", oExp:Refresh() )
@ 6.8, 26.2 BUTTON ">" OF oDlg SIZE 15, 15 ACTION ( cExp += " > ", oExp:Refresh() )
@ 6.8, 29.4 BUTTON "-" OF oDlg SIZE 15, 15 ACTION ( cExp += " - ", oExp:Refresh() )
@ 6.8, 32.6 BUTTON ")" OF oDlg SIZE 15, 15 ACTION ( cExp += " )", oExp:Refresh() )
@ 6.8, 35.8 BUTTON ".F." OF oDlg SIZE 15, 15 ACTION ( cExp += " .F. ", oExp:Refresh() )
@ 7.8, 23 BUTTON "<=" OF oDlg SIZE 15, 15 ACTION ( cExp += " <= ", oExp:Refresh() )
@ 7.8, 26.2 BUTTON ">=" OF oDlg SIZE 15, 15 ACTION ( cExp += " >= ", oExp:Refresh() )
@ 7.8, 29.4 BUTTON "*" OF oDlg SIZE 15, 15 ACTION ( cExp += " * ", oExp:Refresh() )
@ 7.8, 32.6 BUTTON "/" OF oDlg SIZE 15, 15 ACTION ( cExp += " / ", oExp:Refresh() )
@ 7.8, 35.8 BUTTON "$" OF oDlg SIZE 15, 15 ACTION ( cExp += " $ ", oExp:Refresh() )
@ 8.8, 23 BUTTON '"' OF oDlg SIZE 15, 15 ACTION ( cExp += '"', oExp:Refresh() )
@ 8.8, 26.2 BUTTON "!" OF oDlg SIZE 15, 15 ACTION ( cExp += " ! ", oExp:Refresh() )
@ 8.8, 29.4 BUTTON "SP" OF oDlg SIZE 15, 15 ACTION ( cExp += " ", oExp:Refresh() )
@ 8.8, 32.6 BUTTON "," OF oDlg SIZE 15, 15 ACTION ( cExp += ", ", oExp:Refresh() )
@ 8.8, 35.8 BUTTON ":" OF oDlg SIZE 15, 15 ACTION ( cExp += " : ", oExp:Refresh() )
@ 9.8, 23 BUTTON "AND" OF oDlg SIZE 27, 15 ACTION ( cExp += " .and. ", oExp:Refresh() )
@ 9.8, 28.4 BUTTON "OR" OF oDlg SIZE 27, 15 ACTION ( cExp += " .or. ", oExp:Refresh() )
@ 9.8, 33.7 BUTTON "NOT" OF oDlg SIZE 27, 15 ACTION ( cExp += " ! ", oExp:Refresh() )
@ 11.5, 13 BUTTON "&Ok" OF oDlg SIZE 45, 13 ACTION oDlg:End()
@ 11.5, 23 BUTTON "&Cancel" OF oDlg SIZE 45, 13 ACTION oDlg:End() CANCEL
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT IIF( nBack2 < 27, SET_BRUSH(oDlg, nBack2, nGPosD, nGDirectD, .F.), NIL )
return cExp