XBrowse error with oRs:sort

XBrowse error with oRs:sort

Postby Maurizio » Tue Sep 26, 2023 2:37 pm

Hello RAO

if I use sort as in the attached example (adoxbr01.prg )




Code: Select all  Expand view

static function BrowseTable()

   local oRs, oBrw, oFont, oDlg

   oRs   := FW_OpenRecordSet( oCn, "CUSTSMAL" )
   
   
   
   oRs:Sort :=  'CUSTNAME,AGE'


if I just press a letter on xbrowse , xbrowse generates this error ( I use FW June 2022 )

Code: Select all  Expand view
Path and name: C:\FWH_22\samples\ADOXBR01.exe (32 bits)
   Size: 4,903,424 bytes
   Compiler version: Harbour 3.2.0dev (r2006301601)
   FiveWin  version: FWH 22.06
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows 10 64 Bits, version: 6.2, Build 9200

   Time from start: 0 hours 0 mins 8 secs
   Error occurred at: 26-09-2023, 16:29:21
   Error description: (DOS Error -2147352567) WINOLE/1007  Impossibile trovare l'oggetto nell'insieme corrispondente al nome o al numero richiesto. (0x800A0CC1): ADODB.Recordset
   Args:
     [   1] = C   CUSTNAME,AGE
 



This is the sample adoxbr01.prg modified

Code: Select all  Expand view
#include "fivewin.ch"
#include "xbrowse.ch"
#include "hbcompat.ch"      // required

REQUEST DBFCDX

static cMdb    := "tutor01.mdb"
static oCn

//----------------------------------------------------------------------------//

function Main()

   SET DELETED ON
   SET DATE ITALIAN
   SET CENTURY ON

   XbrNumFormat( 'A', .t. )

   ferase( cmdb )
   if .not. File( cMdb )
      FW_CreateMDB( cMdb )
   endif

   CreateTable()
   CopyFromDBF()
   BrowseTable()
   oCn:Close()

return nil

//----------------------------------------------------------------------------//

static function CreateTable()

   local cSql, c

   oCn   := FW_OpenAdoConnection( cMdb )

   TRY
      oCn:Execute( "DROP TABLE CUSTSMAL" )
   CATCH
   END

   TEXT INTO cSql
   CREATE   TABLE CUSTSMAL (
   ID       AUTOINCREMENT PRIMARY KEY,
   CUSTNAME VARCHAR( 30 ),
   MARRIED  BIT,
   AGE      BYTE,
   SALARY   MONEY
   )
   ENDTEXT

   oCn:Execute( cSql )

return nil

//----------------------------------------------------------------------------//

static function CopyFromDBF()

   local oRs

   oRs   := FW_OpenRecordSet( oCn, "CUSTSMAL" )

   USE CUSTOMER NEW ALIAS CUST SHARED READONLY VIA 'DBFCDX'

   do while ! eof() .and. RecNo() < 6

      oRs:AddNew( { "CUSTNAME", "MARRIED", "AGE", "SALARY" }, ;
                  { Left( Trim( CUST->FIRST ) + ' ' + Trim( CUST->LAST ), 30 ), ;
                    CUST->MARRIED, CUST->AGE, CUST->SALARY } )
      SKIP
   enddo

   CLOSE CUST
   oRs:Close()

return nil

//----------------------------------------------------------------------------//

static function BrowseTable()

   local oRs, oBrw, oFont, oDlg

   oRs   := FW_OpenRecordSet( oCn, "CUSTSMAL" )
   
   
   
   oRs:Sort :=  'CUSTNAME,AGE'

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "ADO: SAMPLE"  FONT oFont
   @ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE oRs ;
      PICTURES "999", nil, nil, "99", "9,999,999.99" ;
      AUTOCOLS  ; //AUTOSORT ;
      CELL LINES NOBORDER FASTEDIT

   WITH OBJECT oBrw
      :nEditTypes    := EDIT_GET
      :nStretchCol   := STRETCHCOL_WIDEST
      :Married:SetCheck()
      //
      :bKeyDown      := { |nKey| If( nKey == VK_DELETE, DeleteRow( oBrw ), ;
                                 If( nKey == VK_INSERT, AddEditDlg( oBrw ), nil ) ) }
      //
      :CreateFromcode()
   END

   @ 10, 10 BUTTON "Add"    SIZE 40,12 PIXEL OF oDlg ACTION AddEditDlg( oBrw, .t. )
   @ 10, 55 BUTTON "Edit"   SIZE 40,12 PIXEL OF oDlg ACTION AddEditDlg( oBrw )
   @ 10,100 BUTTON "Delete" SIZE 40,12 PIXEL OF oDlg ACTION DeleteRow( oBrw )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont
   oRs:Close()

return nil

//----------------------------------------------------------------------------//

static function AddEditDlg( oBrw, lAdd )

   local oRs         := oBrw:oRs
   local aFldNames   := { "CUSTNAME", "MARRIED", "AGE", "SALARY" }
   local aVals
   local oDlg, oFont, nRow, lOK := .f.

   DEFAULT lAdd   := ( oBrw:nLen == 0 )

   if lAdd
      aVals   := { Space( 30 ), .f., 0, 0.00 }
   else
      aVals   := oRs:GetRows( 1, 0, aFldNames )[ 1 ]
      oRs:MovePrevious() // IMPORTANT: After Get Rows we need to go back
   endif

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 420,210 PIXEL FONT oFont ;
      TITLE If( lAdd, "ADD NEW CUSTOMER", "EDIT CUSTOMER" )
   nRow           := 10
   @ nRow+1, 10 SAY "Customer Name : " SIZE 60,10 PIXEL OF oDlg RIGHT
   @ nRow,   75 GET aVals[ 1 ] SIZE 115,12 PIXEL OF oDlg VALID ! Empty( aVals[ 1 ] )
   nRow  += 14
   @ nRow+1, 10 SAY "Married : " SIZE 60,10 PIXEL OF oDlg RIGHT
   @ nRow, 75 CHECKBOX aVals[ 2 ] PROMPT "" SIZE 12,12 PIXEL OF oDlg
   nRow  += 14
   @ nRow+1, 10 SAY "Age : " SIZE 60,10 PIXEL OF oDlg RIGHT
   @ nRow,   75 GET aVals[ 3 ] PICTURE "99" SIZE 30,12 PIXEL OF oDlg RIGHT ;
         VALID aVals[ 3 ] > 0

   nRow  += 14
   @ nRow+1, 10 SAY "Salary : " SIZE 60,10 PIXEL OF oDlg RIGHT
   @ nRow,   75 GET aVals[ 4 ] PICTURE "9,999,999.99" SIZE 70,12 PIXEL ;
      OF oDlg RIGHT VALID aVals[ 4 ] > 0
   nRow  += 30

   @ nRow, 115 BUTTON "Cancel" SIZE 40,12 PIXEL OF oDlg CANCEL ACTION ( lOK := .f., oDlg:End() )
   @ nRow, 160 BUTTON "OK"     SIZE 40,12 PIXEL OF oDlg ACTION ( lOK := .t., oDlg:End() )

   ACTIVATE DIALOG oDlg CENTERED

   if lOK
      aVals[ 1 ]    := AllTrim( aVals[ 1 ] )
      TRY
         if lAdd
            oRs:AddNew( aFldNames, aVals )
         else
            oRs:Update( aFldNames, aVals )
         endif
         oBrw:Refresh()
      CATCH
         oRs:CancelUpdate()
         MsgAlert( "Error writing" )
      END
      oBrw:SetFocus()
   endif

return lOk

//----------------------------------------------------------------------------//

static function DeleteRow( oBrw )

   local oRs   := oBrw:oRs
   local nPos

   if !( oRs:Eof .or. oRs:Bof )
      nPos     := oRs:AbsolutePosition
      oRs:Delete()
      oRs:AbsolutePosition := Max( 1, Min( nPos, oRs:RecordCount() ) )
      oBrw:Refresh()
   endif
   oBrw:SetFocus()

return nil

//----------------------------------------------------------------------------//

 
User avatar
Maurizio
 
Posts: 796
Joined: Mon Oct 10, 2005 1:29 pm

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 88 guests

cron