APPEND TO CLIPBOARD

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 6.0


APPEND TO CLIPBOARD (dataType; data)

ParameterTypeDescription
dataTypeString4-character data type string
dataBLOBData to append to the Clipboard

Description

The APPEND TO CLIPBOARD command appends to the Clipboard the data contained in the BLOB data under the data type specified in dataType.

WARNING: The value you pass in dataType is case sensitive, i.e., "abcd" is not equal to "ABCD."

If the BLOB data is correctly appended to the Clipboard, the OK variable is set to 1. Otherwise the OK variable is set to 0 and an error may be generated.

Usually, you will use the APPEND TO CLIPBOARD command to append multiple instances of the same data to the Clipboard or to append data that is not of type TEXT or PICT. To append new data to the Clipboard, you must first clear the Clipboard using the CLEAR CLIPBOARD command.

If you want to clear and append:

text to the Clipboard, use the SET TEXT TO CLIPBOARD command,

a picture to the Clipboard, use the SET PICTURE TO CLIPBOARD command.

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

Example

Using Clipboard 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 CLIPBOARD and GET RECORD FROM CLIPBOARD enable you to treat a whole record as one piece of data to be copied to or from the Clipboard.

      ` SET RECORD TO CLIPBOARD project method
      ` SET RECORD TO CLIPBOARD ( Number )
      ` SET RECORD TO CLIPBOARD ( Table number )

   C_LONGINT($1;$vlField;$vlFieldType)
   C_POINTER($vpTable;$vpField)
   C_STRING(255;$vsDocName)
   C_TEXT($vtRecordData;$vtFieldData)
   C_BLOB($vxRecordData)

      ` Clear the Clipboard (it will stay empty if there is no current record)
   CLEAR CLIPBOARD
      ` 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;Count fields($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 clipboard
      SET TEXT TO CLIPBOARD($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 Clipboard
         ` Note: We use arbitrarily "4Drc" as data type
      APPEND TO CLIPBOARD("4Drc";$vxRecordData)
         ` At this point, the clipboard contains:
         ` (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 CLIPBOARD to the [Employees] table, the Clipboard 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 CLIPBOARD, as follows:

      ` GET RECORD FROM CLIPBOARD method
      ` GET RECORD FROM CLIPBOARD ( Number )
      ` GET RECORD FROM CLIPBOARD ( Table number )
   C_LONGINT($1;$vlField;$vlFieldType;$vlPosCR;$vlPosColon)
   C_POINTER($vpTable;$vpField)
   C_STRING(255;$vsDocName)
   C_BLOB($vxClipboardData)
   C_TEXT($vtClipboardData;$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 clipboard contain a full image record?
         : (Test clipboard("4Drc")>0)
               ` If so, extract the clipboard contents
            GET CLIPBOARD("4Drc";$vxClipboardData)
               ` 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;$vxClipboardData)
               ` 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 clipboard contain TEXT?
         : (Test clipboard("TEXT")>0)
               ` Extract the text from the clipboard        
            $vtClipboardData:=Get text from clipboard
               ` Initialize field number to be increment
            $vlField:=0         
            Repeat 
                  ` Look for the next field line in the text
               $vlPosCR:=Position(CR ;$vtClipboardData)
               If ($vlPosCR>0)
                     ` Extract the field line
                  $vtFieldData:=Substring($vtClipboardData;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
                     ` Clipboard may contain more data than we need...
                  If ($vlField<=Count fields($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
                     $vtClipboardData:=""
                  End if
                     ` Eliminate text that has just been extracted 
                  $vtClipboardData:=Substring($vtClipboardData;$vlPosCR+Length(CR ))
               Else 
                     ` No delimiter found, get out of the loop
                  $vtClipboardData:=""
               End if 
                  ` Repeat as long as we have data
            Until (Length($vtClipboardData)=0)
         Else 
            ALERT("The Clipboard does not any data that can be pasted as a record.")
      End case 
   End if 

See Also

CLEAR CLIPBOARD, SET PICTURE TO CLIPBOARD, SET TEXT TO CLIPBOARD.

System Variables

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

Error Handling

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


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next