FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour A problem with TDatabase using copy() / Past() ?
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
A problem with TDatabase using copy() / Past() ?
Posted: Thu Jan 31, 2019 12:33 PM
Hello,

I noticed a problem using tDatabase Copy() / Paste(aVals)
Wihout selected fields, record 9 is copied to 10



METHOD Copy()
METHOD Paste( aVals )

using Paste() without aVals works
adding aVals doesn't work :-)

Code (fw): Select all Collapse
FUNCTION NET_COPY4 ( nStart, nEnd, lFields )
Local lReturn := .T., aVals := { oCust:Last, oCust:First }

IF nStart = nEnd
    lReturn := .F. 
    MsgAlert( "nStart = nEnd" + CRLF + ;
    "Not possible, to copy Record + ALLTRIM(STR(nRecord)) !", "ERROR")
    RETURN lReturn
ENDIF

oCust:Copy() // copy fields of selected record

IF nEnd > 0 // no append
    oCust:KeyGoTo( nEnd ) // go to defined record
ELSE
    oCust:Append()
ENDIF

oCust:Lock()
IF lFields = .T. // using selected fields
    oCust:Paste(aVals) // doesn't work !
ELSE
    oCust:Paste()  // works
ENDIF
oCust:SAVE()
oCust:Commit()
oCust:UnLock()

RETURN lReturn


maybe something wrong with paste() :-)

regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: A problem with TDatabase using copy() / Past()
Posted: Thu Jan 31, 2019 02:52 PM
TDatabase is already Net Ready.

There is no need for NET_* functions for TDatabase. This is unnecessary and superfluous.

Your code:
Code (fw): Select all Collapse
oCust:Lock()
IF lFields = .T. // using selected fields
    oCust:Paste(aVals)
ELSE
    oCust:Paste()  // Paste( aVals )
ENDIF
oCust:SAVE()
oCust:Commit()
oCust:UnLock()


Where is the need to write the unnecessary code to Lock, Save and Unlock()?
How do you think FWH releases methods without inbuilt locking and unlocking?

FWH methods are simple to use. It is simpler and safer to use the methods as they are provided. Kindly do not complicate them with such unnecessay superflous code.

Now, about the methods Copy() and Paste()

1) Copying all values from one record to another record:
Code (fw): Select all Collapse
WITH OBJECT oDbf
   :Goto( nSrcRec )
   :Copy()
   :GoTo( nDstRec )
   :Paste()
END


2) Copying all values of a record and appending:
(a)
Code (fw): Select all Collapse
WITH OBJECT oDbf
   :GoTo( nSrcRec )
   :Copy()
   :Blank()
   :Paste()
END

(b)
Code (fw): Select all Collapse
WITH OBJECT oDbf
   :GoTo( nSrcRec )
   :Copy()
   :Append( :aCopy )
END


(c)
Copying and pasting selected fields
Code (fw): Select all Collapse
WITH OBJECT oDbf
   :GoTo( nSrcRec )
   aVals := { { "FIRST", :First }, { "LAST", :Last } }
   :GoTo( nDstRec )
   :Paste( aVals )
END

aVals can be a list of values of all fields
Or a 2-dim array with fieldnames and values.
Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: A problem with TDatabase using copy() / Past()
Posted: Thu Jan 31, 2019 03:22 PM
Mr Rao,

thank You very much for the detailed info
I changed the function and it works fine now :-)
I think I can still optimize the other defined functions inside the sample as well.
I'm trying to test most of the tDatabase methods

Code (fw): Select all Collapse
FUNCTION NET_COPY4 ( nStart, nEnd, lFields )
Local lReturn := .T.
Local aVals := {}

IF nStart = nEnd
    lReturn := .F. 
    MsgAlert( "nStart = nEnd" + CRLF + ;
    "Not possible, to copy Record + ALLTRIM(STR(nRecord)) !", "ERROR")
    RETURN lReturn
ENDIF

WITH OBJECT oCust
    aVals := { { "FIRST", :First }, { "LAST", :Last } }
    // :Goto( nSrcRec ) selected from xBrowse
    :Copy() // copy fields of selected record
    IF nEnd > 0
        :GoTo( nEnd )
    ELSE
        oCust:Append()
    ENDIF
    IF lFields = .T.
        :Paste(aVals)
    ELSE
        :Paste()
    ENDIF
END
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: A problem with TDatabase using copy() / Past() ?
Posted: Thu Jan 31, 2019 03:28 PM

We do not think TDatabase methods need external help for optimization.
We recommend using them directly as FWH provided.

Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: A problem with TDatabase using copy() / Past() ?
Posted: Thu Jan 31, 2019 03:43 PM
Mr. Rao,

I dont' want to change or optimize anything.
I only want to create some samples where I can have a look for the practical usage
not wasting time searching inside the class or forum to get detailed infos.
That is the only reason.

I added Your swap - sample to the sample-dialog 3



regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: A problem with TDatabase using copy() / Past() ?
Posted: Thu Jan 31, 2019 08:10 PM

Do we have samples of xbrowse copy / paste ?

Is there a setting that shows a menu on right click to do the copy / paste of a record ( like there is for text ) ?

Are the values saved to the clipboard or are they lost when the xbrowse is closed. For example, if I open an xbrowse ( filtered ) and do a copy of a record, can I close it, then open the same file with a separate filter and do the paste ?

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: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: A problem with TDatabase using copy() / Past() ?
Posted: Thu Jan 31, 2019 08:28 PM

Do we have samples of xbrowse copy / paste ?

This is not a feature of xbrowse. This is a feature of TDatabase.

Is there a setting that shows a menu on right click to do the copy / paste of a record ( like there is for text ) ?

No.

Are the values saved to the clipboard or are they lost when the xbrowse is closed. For example, if I open an xbrowse ( filtered ) and do a copy of a record, can I close it, then open the same file with a separate filter and do the paste ?

This is a feature of TDatabase.
The copied values are stored as data. oDbf:aCopy.
These values are available as long as the object is live.

It does not matter we close xbrowse and reopen in another xbrowse.
With TDatabase we can close and reopen the same dbf after some time.
In all cases the data aCopy is retained.
Code (fw): Select all Collapse
oCust:SetFilter( ... )
oCust:GoTo( x )
oCust:Copy()
// Optionally we can even close and reopen the same dbf later
oCust:Close()
// after some time
oCust:Open()
//
oCust:SetFilter( ... )
oCust:GoTo( xx )
oCust:Paste() // works


The programmer has to develop his own user interface for the copy and paste operations.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: A problem with TDatabase using copy() / Past() ?
Posted: Fri Feb 01, 2019 09:15 PM

Mr. Tim

This thread is about Copy/Paste features of TDatabase.

XBrowse has its own powerful Copy/Paste features using clibboard. Contents of clipboard remain till they are cleared even after closing the xbrowse. These features work not only across different browsers of any data, but also to copy and paste between external applications like Excel, etc.

These features were dicusssed in different threads already. But we will soon make a separate post with complete details.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion