RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TClipboard.Assign Method

Copies an object to the clipboard.

Pascal
procedure Assign(Source: TPersistent); override;
C++
virtual __fastcall Assign(TPersistent * Source);

Use Assign to copy pictures to and from the clipboard. For example, the following code copies the bitmap from a TBitmap instance (Bitmap1) to the clipboard.

Clipboard.Assign(Bitmap1); {Delphi} 

 

Clipboard()->Assign(Bitmap1); // C++

If a bitmap is on the clipboard, the following code copies it to Bitmap1.

Bitmap1.Assign(Clipboard); {Delphi}

 

Bitmap1->Assign(Clipboard()); // C++

The Formats property lists the formats used by the clipboard. Different kinds of graphic object (such as bitmaps and metafiles) have their own formats. Use the HasFormat method to determine whether the information on the clipboard is stored in a format compatible with the object you want to assign it to.  

C++ Examples: 

 

/*
This example uses an image, a button, and a shape component
on a form. When the user clicks the button, an image of the
form is stored in the FormImage variable and copied to the
Clipboard. The image of the form is then copied back to
the image component, producing an interesting result,
especially if the button is clicked multiple times.  Add
ExtCtrls, StdCtrls, and Clipbrd to the uses clause.
}
*/

#include <Clipbrd.hpp>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Graphics::TBitmap *FormImage = GetFormImage();
  try
  {
    Clipboard()->Assign(FormImage);
    Image1->Picture->Assign(Clipboard());
  }
  __finally
  {
    delete FormImage;
  }
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Shape1->Shape = stEllipse;
  Shape1->Brush->Color = clLime;
  Image1->Stretch = true;
}

 

Delphi Examples: 

{
The following line copies the bitmap of a speed button named
SpeedButton1 to the clipboard and then copies the clipboard
to the image picture.  Note that you must add Clipbrd to the
uses clause.
}
uses Clipbrd;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Clipboard.Assign(SpeedButton1.Glyph);
  Image1.Stretch := True;
  Image1.Picture.Assign(Clipboard);
end;
{
This example uses an image, a button, and a shape component
on a form. When the user clicks the button, an image of the
form is stored in the FormImage variable and copied to the
Clipboard. The image of the form is then copied back to
the image component, producing an interesting result,
especially if the button is clicked multiple times.  Add
ExtCtrls, StdCtrls, and Clipbrd to the uses clause.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  FormImage: TBitmap;
begin
  FormImage := GetFormImage;
  try
    Clipboard.Assign(FormImage);
    Image1.Picture.Assign(Clipboard);
  finally
    FormImage.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Shape1.Shape := stEllipse;
  Shape1.Brush.Color := clLime;
  Image1.Stretch := True;
end; 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!