Page 1 of 1

XBrowse 9.2

PostPosted: Mon Mar 23, 2009 6:14 pm
by David Williams
Hi Everyone

oBrw:bLogicLen = {|| Saddocs->(ordkeycount()) }

Is this statement now redundant? I noticed that if I use it, I get an extra column in the browse with the heading BLOGICLEN and the number of records.

Thanks,
David

Re: XBrowse 9.2

PostPosted: Mon Mar 23, 2009 11:42 pm
by Antonio Linares
David,

What FWH version were you using previously to 9.02 ?

Re: XBrowse 9.2

PostPosted: Tue Mar 24, 2009 1:20 am
by nageswaragunupudi
XBrowse never had a DATA bLogicLen. This data is used by WBrowse.

In XBrowse the DATA bKeyCount servers the same purpose.

From version 8.07, any assignment like :
oBrw:<somename> := <somecodeblock> adds a new column with Header as <somename> and bEditValue as <somecodeblock>.

Please see item 7 of whats new in July 2008, reproduced below:
7. In earlier versions a column object can be retrieved by oBrw:oCol( <cHeader> ). Now it is possible to retrieve a
column object with new syntax oBrw:cHeader. It is also possible to create new columns with this syntax.

Example:
oBrw:SalePrice := { || oBrw:Sales:Value / oBrw:Quantity:Value }
Above stament adds a new column with the header 'SALEPRICE' whose value is the value of column with header 'SALES'
divided by the value in the column with header 'QUANTITY'.
oBrw:Sales:nEditType := EDIT_GET
Column with header 'SALES' is set to editmode.

This allows us to write very short self documented as well as highly portable code to create new columns.
Here is an example
Code: Select all  Expand view

#include "fivewin.ch"
#include "xbrowse.ch"

function main()

   local oWnd, oBrw, cAlias
   local nSource

   nSource := Alert( "DataSource", { "DBF", "Access" } )

   if nSource == 1
      cAlias := OpenDBF()
   elseif nSource == 2
      cAlias := OpenAccess()
   else
      return nil
   endif

   DEFINE WINDOW oWnd

   @ 0,0 XBROWSE oBrw OF oWnd ;
      COLUMNS "Last", "Age", "Salary" ;
      ALIAS cAlias

   // now i want to create a new column
   // which is Salary / Age

   oBrw:Ratio := { || oBrw:Salary:Value / oBrw:Age:Value }

   // Advantages:
   // Purpose of the code is very clear.
   // Also the code is very portable
   // Same code works for DBF or ADO
   // without any modification

   // Browse code does not have any code specific to the datasource

   oBrw:CreateFromCode()
   oWnd:oClient := oBrw

   ACTIVATE WINDOW oWnd

return nil

static function OpenDBF()

   USE \FWH\SAMPLES\CUSTOMER ALIAS CUST

return "CUST"

static function OpenAccess()

   local oCon, oRs
   local cStr   := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ;
            "c:\fwh\samples\xbrtest.mdb;User Id=admin;Password=;"

   oCon                     := TOleAuto():new("ADODB.Connection")
   oCon:ConnectionString   := cStr
   TRY
      oCon:Open()
   CATCH
      MsgInfo('Connect Fail')
      QUIT
   END

   oRs                     := TOleAuto():new( "ADODB.RecordSet" )
   oRs:ActiveConnection    := oCon
   oRs:Source              := 'CUSTOMER'
   oRs:LockType            := 4            // adLockOptimistic
   oRs:CursorLocation      := 3            //adUseClient
   oRs:CacheSize           := 100
   TRY
      oRs:Open()
   CATCH
      MsgStop('Access Table Open Failure')
      QUIT
   END

return oRs
 


Now you can understand why XBrowse is creating a new column with Header bLogicLen.

Re: XBrowse 9.2

PostPosted: Wed Mar 25, 2009 8:14 am
by David Williams
Antonio and G

I previously used TCBrowse from Luis Klaus Mantilla and I'm converting to xBrowse. Thank you for the full explanation.

Regards
David

Re: XBrowse 9.2

PostPosted: Wed Mar 25, 2009 8:18 am
by nageswaragunupudi
If you are converting TCBrowse to TXbrowse, if you stick to Command syntax, the conversion will be pretty fast and reliable. Saves lot of develpment time. Command syntax of TCBrowe and TXBrowse are purposefully made similar for that reason.

Also you can remove lot of old code if you use the extended builtin features of XBrowse. It is less code and more work with XBrowse.