4D v14.3

APPEND DATA TO PASTEBOARD

Home

 
4D v14.3
APPEND DATA TO PASTEBOARD

APPEND DATA TO PASTEBOARD 


 

APPEND DATA TO PASTEBOARD ( dataType ; data ) 
Parameter Type   Description
dataType  String in Type of data to be added
data  BLOB in Data to append to the pasteboard

The APPEND DATA TO PASTEBOARD command appends to the pasteboard the data contained in the BLOB data under the data type specified in dataType.

Note: In the case of copy/paste operations, the pasteboard is equivalent to the Clipboard.

In dataType, pass a value specifying the type of data to be added. You can pass a 4D signature, a UTI type (Mac OS), a format name/number (Windows), or a 4-character type (compatibility). For more information about these types, please refer to the Managing Pasteboards section.

Note for Windows users: When the command is used with Text type data (dataType is "TEXT", com.4d.private.text.native or com.4d.private.text.utf16), the string contained in the BLOB parameter data must end with the NULL character under Windows.

Usually, you will use the APPEND DATA TO PASTEBOARD command to append multiple instances of the same data to the pasteboard or to append data that is not text or a picture. To append new data to the pasteboard, you must first clear the pasteboard using the CLEAR PASTEBOARD command.

If you want to clear and append:

However, note that if a BLOB actually contains some text or a picture, you can use the APPEND DATA TO PASTEBOARD command to append a text or a picture to the pasteboard.

Example  

Using Pasteboard commands and BLOBs, you can build sophisticated Cut/Copy/Paste schemes that deal with structured data rather than a unique piece of data. In the following example, the two project methods SET RECORD TO PASTEBOARD and GET RECORD FROM PASTEBOARD enable you to treat a whole record as one piece of data to be copied to or from the pasteboard.

  ` SET RECORD TO PASTEBOARD project method
  ` SET RECORD TO PASTEBOARD ( Number )
  ` SET RECORD TO PASTEBOARD ( Table number )
 
 C_LONGINT($1;$vlField;$vlFieldType)
 C_POINTER($vpTable;$vpField)
 C_STRING(255;$vsDocName)
 C_TEXT($vtRecordData;$vtFieldData)
 C_BLOB($vxRecordData)
 
  ` Clear the pasteboard (it will stay empty if there is no current record)
 CLEAR PASTEBOARD
  ` Get a pointer to the table whose number is passed as parameter
 $vpTable:=Table($1)
  ` If there is a current record for that table
 If((Record number($vpTable->)>=0)|(Is new record($vpTable->)))
  ` Initialize the text variable that will hold the text image of the record
    $vtRecordData:=""
  ` For each field of the record:
    For($vlField;1;Get last field number($1))
  ` Get the type of the field
       GET FIELD PROPERTIES($1;$vlField;$vlFieldType)
  ` Get a pointer to the field
       $vpField:=Field($1;$vlField)
  ` Depending on the type of the field, copy (or not) its data in the appropriate manner
       Case of
          :(($vlFieldType=Is alpha field)|($vlFieldType=Is text))
             $vtFieldData:=$vpField->
          :(($vlFieldType=Is real)|($vlFieldType=Is integer)|($vlFieldType=Is LongInt)
             |($vlFieldType=Is date)|($vlFieldType=Is time))
             $vtFieldData:=String($vpField->)
          :($vlFieldType=Is Boolean)
             $vtFieldData:=String(Num($vpField->);"Yes;;No")
          Else
  ` Skip and ignore other field data types
             $vtFieldData:=""
       End case
  ` Accumulate the field data into the text variable holding the text image of the record
       $vtRecordData:=$vtRecordData+Field name($1;$vlField)+":"+Char(9)+$vtFieldData+CR
  ` Note: The method CR returns Char(13) on Macintosh and Char(13)+Char(10) on Windows
    End for
  ` Put the text image of the record into the pasteboard
    SET TEXT TO PASTEBOARD($vtRecordData)
  ` Name for scrap file in Temporary folder
    $vsDocName:=Temporary folder+"Scrap"+String(1+(Random%99))
  ` Delete the scrap file if it exists (error should be tested here)
    DELETE DOCUMENT($vsDocName)
  ` Create scrap file
    SET CHANNEL(10;$vsDocName)
  ` Send the whole record into the scrap file
    SEND RECORD($vpTable->)
  ` Close the scrap file
    SET CHANNEL(11)
  ` Load the scrap file into a BLOB
    DOCUMENT TO BLOB($vsDocName;$vxRecordData)
  ` We longer need the scrap file
    DELETE DOCUMENT($vsDocName)
  ` Append the full image of the record into the pasteboard
  ` Note: We use arbitrarily "4Drc" as data type
    APPEND DATA TO PASTEBOARD("4Drc";$vxRecordData)
  ` At this point, the pasteboardcontains:
  ` (1) A text image of the record (as shown in the screen shots below)
  ` (2) A whole image of the record (Picture, Subfile and BLOB fields included)
 End if

While entering the following record:

If you apply the method SET RECORD TO PASTEBOARD to the [Employees] table, the pasteboard will contain the text image of the record, as shown, and also the whole image of the record.

You can paste this image of the record to another record, using the method GET RECORD FROM PASTEBOARD, as follows:

  ` GET RECORD FROM PASTEBOARDmethod
  ` GET RECORD FROM PASTEBOARD( Number )
  ` GET RECORD FROM PASTEBOARD( Table number )
 C_LONGINT($1;$vlField;$vlFieldType;$vlPosCR;$vlPosColon)
 C_POINTER($vpTable;$vpField)
 C_STRING(255;$vsDocName)
 C_BLOB($vxPasteboardData)
 C_TEXT($vtPasteboardData;$vtFieldData)
 
  ` Get a pointer to the table whose number is passed as parameter
 $vpTable:=Table($1)
  ` If there is a current record
 If((Record number($vpTable->)>=0)|(Is new record($vpTable->)))
    Case of
  ` Does the pasteboard contain a full image record?
       :(Pasteboard data size("4Drc")>0)
  ` If so, extract the pasteboard contents
          GET PASTEBOARD DATA("4Drc";$vxPasteboardData)
  ` Name for scrap file in Temporary folder
          $vsDocName:=Temporary folder+"Scrap"+String(1+(Random%99))
  ` Delete the scrap file if it exists (error should be tested here)
          DELETE DOCUMENT($vsDocName)
  ` Save the BLOB into the scrap file
          BLOB TO DOCUMENT($vsDocName;$vxPasteboardData)
  ` Open the scrap file
          SET CHANNEL(10;$vsDocName)
  ` Receive the whole record from the scrap file
          RECEIVE RECORD($vpTable->)
  ` Close the scrap file
          SET CHANNEL(11)
  ` We longer need the scrap file
          DELETE DOCUMENT($vsDocName)
  ` Does the pasteboard contain TEXT?
       :(Pasteboard data size("TEXT")>0)
  ` Extract the text from the pasteboard
          $vtPasteboardData:=Get text from pasteboard
  ` Initialize field number to be increment
          $vlField:=0
          Repeat
  ` Look for the next field line in the text
             $vlPosCR:=Position(CR;$vtPasteboardData)
             If($vlPosCR>0)
  ` Extract the field line
                $vtFieldData:=Substring($vtPasteboardData;1;$vlPosCR-1)
  ` If there is a colon ":"
                $vlPosColon:=Position(":";$vtFieldData)
                If($vlPosColon>0)
  ` Take only the field data (eliminate field name)
                   $vtFieldData:=Substring($vtFieldData;$vlPosColon+2)
                End if
  ` Increment field number
                $vlField:=$vlField+1
  ` Pasteboard may contain more data than we need...
                If($vlField<=Get last field number($vpTable))
  ` Get the type of the field
                   GET FIELD PROPERTIES($1;$vlField;$vlFieldType)
  ` Get a pointer to the field
                   $vpField:=Field($1;$vlField)
  ` Depending on the type of the field, copy (or not) the text in the appropriate manner
                   Case of
                      :(($vlFieldType=Is alpha field)|($vlFieldType=Is text))
                         $vpField->:=$vtFieldData
                      :(($vlFieldType=Is real)|($vlFieldType=Is integer)|($vlFieldType=Is LongInt))
                         $vpField->:=Num($vtFieldData)
                      :($vlFieldType=Is date)
                         $vpField->:=Date($vtFieldData)
                      :($vlFieldType=Is time)
                         $vpField->:=Time($vtFieldData)
                      :($vlFieldType=Is Boolean)
                         $vpField->:=($vtFieldData="Yes")
                      Else
  ` Skip and ignore other field data types
                   End case
                Else
  ` All fields have been assigned, get out of the loop
                   $vtPasteboardData:=""
                End if
  ` Eliminate text that has just been extracted
                $vtPasteboardData:=Substring($vtPasteboardData;$vlPosCR+Length(CR))
             Else
  ` No delimiter found, get out of the loop
                $vtPasteboardData:=""
             End if
  ` Repeat as long as we have data
          Until(Length($vtPasteboardData)=0)
       Else
          ALERT("The pasteboard does not any data that can be pasted as a record.")
    End case
 End if

If the BLOB data is correctly appended to the pasteboard, OK is set to 1; otherwise OK is set to 0 and an error may be generated.

If there is not enough memory to append the BLOB data to the pasteboard, an error -108 is generated.

 
PROPERTIES 

Product: 4D
Theme: Pasteboard
Number: 403

The OK variable is changed by the commandThis command modifies the Error system variable

 
HISTORY 

Modified: 4D v11 SQL

 
SEE ALSO 

CLEAR PASTEBOARD
SET PICTURE TO PASTEBOARD
SET TEXT TO PASTEBOARD

 
ARTICLE USAGE

4D Language Reference ( 4D v12.4)
4D Language Reference ( 4D v11 SQL Release 6)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v13.5)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)