FMX.CopyPaste Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to get access to the system's clipboard, copy text or images into the clipboard and paste either text or images from the clipboard.

Location

You can find the CopyPaste sample project at:

Description

The CopyPaste sample demonstrates how to create applications that use the system's clipboard to copy and paste text or images. The sample uses IFMXClipboardService to iteract with the system clipboard. Concretelly the SetClipboard method is used to put data into the system clipboard and the GetClipboard method is used to return data from the system clipboard.

Note: Windows, OSX, iOS platforms provides copy/paste of both text and images. Android platform only provides text copy/paste.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: CopyPaste.dproj.
    • C++: CopyPaste.cbproj.
  2. Select the target platform, iOS and Android supported.
  3. Press F9 or choose Run > Run.
  4. Interact with the sample:
    • The sample shows two tabs: COPY and PASTE.
    • Stand on the COPY tab and write some text in the box under the Input text to copy label. Then, the Copy data button is enabled.
    • See the written text on the rectangle below.
    • Choose whether you want to copy the text as text or as image. Then, select the corresponding button.
      Note: if you select to copy the text as image, the sample makes a screenshot of the rectangle with the text.
    • Move to the PASTE control and click on the Paste button. If you copied the text as text, the text appears on the label next to the Paste button. If you copied the text as an image, the image appears on the rectangle below the Paste button.

Files

File in Delphi File in C++ Contains

CopyPasteDemo.dproj

CopyPasteDemo.cbproj

The project itself.

fmMain.fmx

fmMain.fmx

The main form where the components are located.

fmMain.pas

CopyPasteDemoPCH.h, CopyPasteDemo.cpp

Used to define and implement the sample.

Classes

TForm3 is the main form that represents the main window of the sample. It contains the following components:

Implementation

  • The sample uses TTabControl to add a control with multiple tab settings to a FireMonkey form.
  • The sample uses TPanel to hold multiple controls for organizing purposes.
  • The sample uses TEdit to provide the user an edit box to write text.
  • The sample uses TButton to enable or activate some related application actions like copy data or paste the data.
  • The sample uses TRectangle to show the written text.
  • The sample uses TImage to display and define 2D image components.

The sample has 2 tab items, one to type text and copy it into the clipboard and the other to paste the data from the clipboard.

When you run the application, the sample shows the first TTabItem labeled as COPY. It contains a TEdit, a TRectangle, two TRadioButtons labeled as Copy as text and Copy as image and a TButton labeled as Copy data. First, the Copy data button is disabled. It gets enabled when you type text in the TEdit box. The text you type in the TEdit box is shown on the TRectangle. Before clicking on the Copy data button, choose whether you want to copy the text as text or as image; then, select the corresponding TRadioButton. On the one hand, If you choose the Copy as text radio button, the sample uses SetClipboard to put the data of the TEdit box into the clipboard. On the other hand, if you choose the Copy as image radio button, the sample uses the MakeScreenshot method to make a screenshot of the TRectangle component and then, uses SetClipboard to put the image generated by the screenshot into the clipboard.

The second TTabItem labeled as PASTE contains a TButton, a TLabel and a TImage components. When you click on the Paste button, the samples uses the GetClipboard method to return data from the system clipboard. If the clipboard contains text, it is pasted into the TLabel component. However, if the clipboard contains an image, it is pasted into the TImage component.

Uses

See Also

Samples

Personal tools
Assistance