FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour database object
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
database object
Posted: Wed Nov 14, 2012 08:23 PM
To all,
I think Modified() with method blank() does not work correctly.
In this case modified() checks always agains record number 1.
Best Retards,
Otto

Code (fw): Select all Collapse
METHOD Modified() CLASS TDataBase

   local n

   if ::lBuffer
      for n := 1 to ( ::nArea )->( FCount() )
         if ! ( ::cAlias )->( FieldGet( n ) ) == ::aBuffer[ n ]
            return .t.
         endif
      next
   endif

return .f.
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: database object
Posted: Thu Nov 15, 2012 10:11 AM
As this is my personal knowledge base, too I post my work around here:

Regards,
Otto

Code (fw): Select all Collapse
::oKBuch := TData():New( , "datawin\kasse" )
    ::oKBuch:use()
    ::oKBuch:blank()

    aBufferBlank := AClone( ::oKBuch:abuffer )
    

// if you set default values
    ::oKBuch:datum := date()
        
    aBufferBlank[ 2 ] := ::oKBuch:Beleg
    aBufferBlank[ 9 ] := ::oKBuch:datum



    lreturn := ModifiedBlank( oSelf:oKBuch:nArea,aBufferBlank, oSelf:oKBuch:aBuffer )


static function ModifiedBlank( nArea,aBufferBlank, aBuffer ) 

   local n
       
      for n := 1 to ( nArea )->( FCount() )
      
         if ! aBuffer[ n ] == aBufferBlank[ n ]
         msginfo(aBuffer[ n ])
            return .t.
         endif
      next

return .f.

//----------------------------------------------------------------------------//
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: database object
Posted: Thu Nov 15, 2012 11:17 AM

Otto,

Method Blank() does not change the record number, so method Modified() should work fine.

Maybe the database is being displayed on a browse and the browse is changing the record number ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: database object
Posted: Thu Nov 15, 2012 11:31 AM

Hello Antionio,
I am sorry.
I use TDATA from James and for compatibility reason still a database.prg with this

METHOD Blank( nRecNo ) INLINE ( ::nArea )->( nRecNo := RecNo(),;
DBGoBottom(), ;
DBSkip( 1 ), ;
::Load(),;
DBGoTo( nRecNo ) )

I try to check the new method in database.prg.
Best regards,
Otto

I

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: database object
Posted: Thu Nov 15, 2012 11:53 AM

Hello Antonio,
I check again the "method modified".
What I do not understand is how can ( ::cAlias )->( FieldGet( n ) ) read a record which does not exist in the database yet.
Best regards,
Otto

METHOD Modified() CLASS TDataBase

local n

if ::lBuffer
for n := 1 to ( ::nArea )->( FCount() )
if ! ( ::cAlias )->( FieldGet( n ) ) == ::aBuffer[ n ]
return .t.
endif
next
endif

return .f.

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: database object
Posted: Thu Nov 15, 2012 04:19 PM

Hello Antonio,

::FieldGet( 1 ) would Show the right value.

( ::cAlias )->( FieldGet( n ) ) Shows the value of the first row.

Can you please help me.
Best regards,
Otto

METHOD Modified() CLASS TDataFWH

local n

logfile("log.txt",{ ::recno(), "modified" } )

logfile("log.txt",{ "FieldGet", ::FieldGet( 1 ) } )

for n := 1 to Len( ::aFldNames )

  if ! ( ::cAlias )->( FieldGet( n ) ) == ::aBuffer[ n ]
        msginfo(( ::cAlias )->( FieldGet( n ) ))
        msginfo(::aBuffer[ n ]) 
     return .t.
  endif

next
return .f.

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: database object
Posted: Thu Nov 15, 2012 04:53 PM
Hello Antonio,
if I check immediately afte assigning ::abuffer in METHOD Blank()
( ::cAlias )->( FieldGet( 1 ) ) returns the value of the first record in the database.
Are you sure modified is working if you add a record using blank()
Best regards,
Otto


Code (fw): Select all Collapse
METHOD Blank() CLASS TDataFWH

   
   if ::lBuffer
      AEval( ::aBuffer, { |u,i| ::aBuffer[ i ] := uValBlank( u ) } )
   endif


    logfile("log.txt",{ ::recno(), "*** Blank"  } )
 
    logfile("log.txt",{ "::FieldGet  ->", ::FieldGet( 1 )  } )
 
    logfile("log.txt",{ "FieldGet  ->", ( ::cAlias )->( FieldGet( 1 ) )  }  )
  
    logfile("log.txt",{ "aBuffer  ->", ::aBuffer[ 1 ]   }  )

    logfile("log.txt",{ ::recno(), "*** Ende"  } )
 
return .f.

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


15.11.2012 05:42:12: 1 *** Blank
15.11.2012 05:42:12: ::FieldGet ->
15.11.2012 05:42:12: FieldGet -> Gute Anreise
15.11.2012 05:42:12: aBuffer ->
15.11.2012 05:42:12: 1 *** Ende
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: database object
Posted: Thu Nov 15, 2012 06:18 PM

Otto,

I'm also using tData. Are you using tRecord also ? When using an xbrowse, and editing a particular row, I have the values in a tRecord. Thus I never have a problem with saves.

I've used it for many years ( and James did make some revisions along the way ), and have no problems.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: database object
Posted: Thu Nov 15, 2012 06:43 PM
Tim,
here is a test which shows the wrong behavior.
Click on the button without inserting something into the get field and method modified returns true.
Best regards,
Otto

Code (fw): Select all Collapse
function testTdata()
   LOCAL oDlg, oGet
   LOCAL oKBuch

   oKBuch := TData():New( ,  "clientes" )
    oKBuch:use()
    oKBuch:blank()

         DEFINE DIALOG oDlg ;
           TITLE "TGet from " ;
            FROM 10, 10 ;
              TO 500, 800 ;
           PIXEL



        @ 10,20 ;
         SAY "Text..:" ;
          OF oDlg ;
       PIXEL

       @ 20,160 ;
         GET oGet ;
         VAR oKBuch:nombre ;
          OF oDlg ;
       PIXEL ;
        SIZE 160, 10

  
       @ 40,20 ;
      BUTTON "Modified Yes/no" ;
      ACTION ( iif ( oKBuch:Modified() = .T., Msginfo( "geändert" ), MsgInfo("nicht geändert"  ) ) ) ;
          OF oDlg ;
       PIXEL


   ACTIVATE DIALOG oDlg CENTERED
   
  
return nil

//------------------------------------------------------------------------//
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: database object
Posted: Fri Nov 16, 2012 12:36 AM

Otto,

As James explained it to me, blank simply empties the buffers. You didn't add a record ( obj:append( ) ) so you wouldn't have a record number.

tRecord may resolve your problems because it will track a record number and always make sure you write to it.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: database object
Posted: Fri Nov 16, 2012 07:36 AM

:append()

Hello Tim,
thank you for your explanation.
As in the moment of opening a dialog to insert a new record you never know if a user finishes entering you can’t append a record.
If he breaks off you have to delete the record in the database.
To delete records in a database concerning data which is responsible for calculating taxes is prohibited from law here.
Therefore you only :append a record if you really want to.

There should be a DATA inside Tdatabase.prg showing that you enter data in a blank record.
Best regards,
Otto

Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: database object
Posted: Fri Nov 16, 2012 10:02 PM

tRecord will do that for you. Create a new tRecord object, and issue blank( ). That gives you clear data. Because there is no record number, when you go to save it, it will do the append( ) at that time.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: database object
Posted: Fri Nov 16, 2012 10:18 PM

Hello Tim,
thank you. I will look into the TRecord object.
Best regards,
Otto

Continue the discussion