xBrowse and a codeblock column

xBrowse and a codeblock column

Postby Rick Lipkin » Tue Jun 30, 2009 7:07 pm

To All

I have a listbox that I want to convert to xBrowse.. with using the COLUMNS syntax .. I have a code block that returns a value that populates a column. ( DispType( oRsVEH ) )

It is that codeblock that errors and I do not know of a way to return the value I want to display in the specific column .. here is the code :

Also notice .. my old listbox code turned a row a specific color nased on a certain data condition .. i have not been able to figure that one out yet either ..

Rick Lipkin

Code: Select all  Expand view

cTITLE := "SELECT * from VEHICLES where AGENCY = '"+xAGENCY+"'"

nWd := GetSysMetrics(0) * .50
nHt := GetSysMetrics(1) * .8

lOK := .F.
DEFINE ICON oICO RESOURCE "KEY"

DEFINE WINDOW oWnd1                        ;
      FROM 10,10 to nHt, nWd PIXEL         ;
      TITLE cTITLE                         ;
      MENU BuildMenu(oRsVEH)               ;
      ICON oICO                            ;
      NOMINIMIZE                           ;
      NOZOOM                               ;
      MDICHILD

@ 0, 0 xBROWSE oBrw of oWnd1               ;
       RECORDSET oRsVeh                    ;
       COLUMNS 'VNUMBER',                  ;
               EVAL( {|x|Disptype( oRsVeh) } ),;   //  <-- error here
              'LICENSE',                   ;
              'AGENCY',                    ;
              'MAKE',                      ;
              'TYPE',                      ;
              'YEAR',                      ;
              'PROG',                      ;
              'MOTORPOOL',                 ;
              'REGION',                    ;
              'LASTSERVCE',                ;
              'NEXTSERVCE',                ;
              'NEXTMILAGE',                ;
              'SERIALNUMB',                ;
              'ACTIVE'                     ;
       COLSIZES 48,50,80,50,120,120,55,95,95,140,80,80,80,190,30  ;
       HEADERS "Vnum",                     ;
               "Type",                     ;
               "License",                  ;
               "Agency",                   ;
               "Make",                     ;
               "Model",                    ;
               "Year",                     ;
               "Program",                  ;
               "Mtrpool",                  ;
               "Location",                 ;
               "LastServ",                 ;
               "NextServ",                 ;
               "NextMilage",               ;
               "Serial#",                  ;
               "Act"                       ;
       AUTOSORT AUTOCOLS LINES CELL

       oBrw:CreateFromCode()
       oWnd1:oClient := oBrw

        oBrw:bLDblClick := { |nRow,nCol | _VehView( "V", oRsVeh ) }
     *  oBrw:bKeyDown   := { |nKey| _Manual( nKey,oRs ) }


     *  oBrw:nClrText      := { || SelColor( oRsVEH:Fields("readonly"):Value, "F", 1 ) }
     *  oBrw:nClrPane      := { || SelColor( oRsVEH:Fields("readonly"):Value, "B", 1 ) }
     *  oBrw:nClrForeFocus := { || SelColor( oRsVEH:Fields("readonly"):Value, "F", 2 ) }
     *  oBrw:nClrBackFocus := { || SelColor( oRsVEH:Fields("readonly"):Value, "B", 2 ) }

ACTIVATE WINDOW oWND1 ;
         ON INIT( oBrw:SetFocus(), .F. ) ;
         VALID ( IIF( !lOK, _VehClose(.T., oRsVEH), .F. ))

RETURN( .T. )

//------------------------------
Static FUnc SelColor( cSTATUS, cTYPE, nTYPE )

LOCAL nCOLOR := CLR_BLACK

DO CASE
CASE cTYPE = 'F' .and. nTYPE = 1       // foreground
     IF cSTATUS = "Y"
        nCOLOR := CLR_WHITE
     ELSE
        nCOLOR := CLR_BLACK
     ENDIF
CASE cTYPE = 'B' .and. nTYPE = 1       // background
     IF cSTATUS = "Y"
        nCOLOR := RGB(179,203,204)
     ELSE
        nCOLOR := CLR_WHITE
     ENDIF

CASE cTYPE = 'F' .and. nTYPE = 2       // foreground
     IF cSTATUS = "Y"
        nCOLOR := RGB(255,0,0 ) //CLR_WHITE
     ELSE
        nCOLOR := CLR_BLACK
     ENDIF
CASE cTYPE = 'B' .and. nTYPE = 2       // background
     IF cSTATUS = "Y"
        nCOLOR := RGB(179,203,204)
     ELSE
        nCOLOR := rgb(192,192,192) //CLR_WHITE
     ENDIF


ENDCASE

RETURN( nCOLOR )


//----------------------
Static Func DispType( oRsVEH )

Local cTYPE := SPACE(5)

DO CASE
CASE oRsVEH:Fields("V_TYPE"):Value = "V"
     cTYPE := "VEH"
CASE oRsVEH:Fields("V_TYPE"):Value = "E"
     cTYPE := "EQUIP"
CASE oRsVEH:Fields("V_TYPE"):Value = "B"
     cTYPE := "BOAT"
OTHERWISE
     cTYPE := "UNK"
ENDCASE

RETURN( cTYPE )

//----------------------
Static Func DispMemo( oRsVEH )

Local cMEMO, cMESSAGE

cMEMO    := oRsVeh:Fields("memo"):Value
cMESSAGE := "  "

IF empty(alltrim(cMEMO))
ELSE
   cMESSAGE := " see memo "
ENDIF

RETURN( cMESSAGE )

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xBrowse and a codeblock column

Postby nageswaragunupudi » Wed Jul 01, 2009 3:32 am

Mr Rick

COLUMNS syntax can be used only if a field exactly by that name ( case insensitive ) exists in the recordset.

In your case, I suggest the following alternatives:
1) Use a dummy name instead of the codeblock for the second column and after defining the xbrowse assign the codeblock as
oBrw:aCols[ 2 ]:bEditValue := {|x|Disptype( oRs:Fields('Veh"):Value ) }
2) Omit defining the second column totally while initially defining the browse.
Later add the second column with this syntax:
ADD TO oBrw AT 2 DATA DispType( oRs:Fields('Veh'):Value ) HEADER 'Type', etc...
Above statement *inserts* the column at 2nd position.
3) For defining columns with expressions, you can use FIELDS clause instead of COLUMNS clause. If you recollect that is the way earlier WBrowse and TCBrowse are defined with FIELDS clauses. We can also mix COLUMNS and FIELDS clauses in XBrowse, but that is a bit combursome.

I personally advise the second method above
Regards

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

Re: xBrowse and a codeblock column

Postby Rick Lipkin » Wed Jul 01, 2009 12:56 pm

Rao

I origionaly used the FIELDS clause but the result was not the 'fields' I defined but each column in the recordset .. not what I had expected .. I went back to the COLUMN expression and that is where I ran the road-block.

Let me soak up your suggestion and do some tests .. also, curious about the row colors based on a a specific result in a field .. your thoughts ??

Rick
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xBrowse and a codeblock column

Postby nageswaragunupudi » Wed Jul 01, 2009 5:25 pm

Code: Select all  Expand view
oBrw:bClrStd      := { || If( oRsVeh:Fields( 'readonly' ):Value = 'Y', ;
                         { CLR_WHITE, RGB(179,203,204) }, ;
                         { CLR_BLACK, CLR_WHITE } ) }

oBrw:bClrSelFocus := { || If( oRsVeh:Fields( 'readonly' ):Value = 'Y', ;
                          { RGB(255,0,0 ), RGB(179,203,204) }, ;
                          { CLR_BLACK, RGB(192,192,192) } ) }
 
Regards

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

Re: xBrowse and a codeblock column

Postby Rick Lipkin » Wed Jul 01, 2009 7:46 pm

Rao

Thank you .. worked great !!

Rick
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], nageswaragunupudi and 102 guests