eDocEngine VCL
Create documents and reports in 18 formats
Compatibility
Delphi C++Builder

Programming the Windows Clipboard using eDocEngine

Learn how to use the clipboard engine.
By Ashwini

The Windows clipboard allows you to temporarily store content in formats such as text, bitmap, metafile, and wave.

eDocEngine's gtClipboard class supports text, Software Arts' Data Interchange Format (used in VisiCalc), Microsoft's Symbolic Link (SYLK) format, bitmap, Windows Metafile (WMF), and Enhanced Metafile (EMF).

After you create a gtClipboard object, you can add elements such as text, images, shapes, tables, watermarks and stamps to it. The elements supported by the format will be copied to the Windows clipboard.

After the content has been copied to the Windows clipboard in a particular format, you can open any application that supports that format, open a new document, and do a "Paste" operation. The Windows clipboard contents will be copied to the document right away!

To illustrate this, here is a small application that places some text and an image into the clipboard in a given format.

After the button is clicked, you can open an image-editing application and do the "Paste" operation.

And, here is the code snippet where all the action is.

type
  TForm1 = class(TForm)
    // The "Copy to Clipboard" button
    Button1: TButton;
    // eDocEngine Clipboard engine component
    gtClipboard1: TgtClipboard;
    OpenDialog1: TOpenDialog;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Memo1: TMemo;
    // The "Load a picture" button
    Button2: TButton;
    // The "Select the output format" list
    ComboBox1: TComboBox;
    Label2: TLabel;
    Shape1: TShape;
    Image1: TImage;
...

procedure TForm1.Button1Click(Sender: TObject);
var
  LStr: String;
begin
  LStr := Memo1.Lines.Text;

  case ComboBox1.ItemIndex of
    0: gtClipboard1.OutputFormat := ofText;
    1: gtClipboard1.OutputFormat := ofSYLK;
    2: gtClipboard1.OutputFormat := ofDIF;
    3: gtClipboard1.OutputFormat := ofBMP;
    4: gtClipboard1.OutputFormat := ofMetafile;
  end;

  // Use the clipboard engine component
  with gtClipboard1 do
  begin
    BeginDoc;
      BeginPara;
        // Write the text
        TextOut(LStr);
        // Render the selected image
        DrawImage(1, 1, Image1.Picture.Graphic);
      EndPara;
    EndDoc;
   end;
end;

// Allow the user select an image and display it
// on the form
procedure TForm1.Button2Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    Image1.Picture.LoadFromFile(OpenDialog1.FileName);
end;
---o0O0o---

Downloads:

Privacy | Legal | Feedback | Newsletter © 2002-2010 Gnostice Information Technologies Private Limited. All rights reserved.

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows users are advised to use Microsoft ClearType Tuning for optimal experience. Linux and other users can enable font smoothing, as supported by their OS. Also, please use the latest version of a standards-compliant browser such as Opera, FireFox, Chrome or Safari.