A problem with TDatabase using copy() / Past() ?

A problem with TDatabase using copy() / Past() ?

Postby ukoenig » 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

Image

METHOD Copy()
METHOD Paste( aVals )

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

Code: Select all  Expand view

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 :?:
Last edited by ukoenig on Sun Feb 03, 2019 5:15 pm, edited 3 times in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: A problem with TDatabase using copy() / Past()

Postby nageswaragunupudi » Thu Jan 31, 2019 2:52 pm

TDatabase is already Net Ready.

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

Your code:
Code: Select all  Expand view

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: Select all  Expand view

WITH OBJECT oDbf
   :Goto( nSrcRec )
   :Copy()
   :GoTo( nDstRec )
   :Paste()
END
 


2) Copying all values of a record and appending:
(a)
Code: Select all  Expand view

WITH OBJECT oDbf
   :GoTo( nSrcRec )
   :Copy()
   :Blank()
   :Paste()
END
 

(b)
Code: Select all  Expand view

WITH OBJECT oDbf
   :GoTo( nSrcRec )
   :Copy()
   :Append( :aCopy )
END
 


(c)
Copying and pasting selected fields
Code: Select all  Expand view

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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: A problem with TDatabase using copy() / Past()

Postby ukoenig » Thu Jan 31, 2019 3:22 pm

Mr Rao,

thank You very much for the detailed info
I changed the function and it works fine now :D
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: Select all  Expand view

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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: A problem with TDatabase using copy() / Past() ?

Postby nageswaragunupudi » Thu Jan 31, 2019 3: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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: A problem with TDatabase using copy() / Past() ?

Postby ukoenig » Thu Jan 31, 2019 3: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

Image

regards
Uwe :D
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: A problem with TDatabase using copy() / Past() ?

Postby TimStone » Thu Jan 31, 2019 8: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
User avatar
TimStone
 
Posts: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: A problem with TDatabase using copy() / Past() ?

Postby nageswaragunupudi » Thu Jan 31, 2019 8: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: Select all  Expand view

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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: A problem with TDatabase using copy() / Past() ?

Postby nageswaragunupudi » Fri Feb 01, 2019 9: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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 76 guests