Adding Clipboard Formats

From RAD Studio
Jump to: navigation, search

Go Up to Adding Component Editors


By default, when a user chooses Copy while a component is selected in the IDE, the component is copied in Delphi internal format. It can then be pasted into another form or data module. Your component can copy additional formats to the Clipboard by overriding the Copy method.

For example, the following Copy method allows a TImage component to copy its picture to the Clipboard. This picture is ignored by the Delphi IDE, but can be pasted into other applications.

Delphi:

procedure TMyComponent.Copy;
var
  MyFormat : Word;
  AData,APalette : THandle;
begin
  TImage(Component).Picture.Bitmap.SaveToClipBoardFormat(MyFormat, AData, APalette);
  ClipBoard.SetAsHandle(MyFormat, AData);
end;

C++:

void __fastcall TMyComponentEditor::Copy(void)
{
    WORD AFormat;
    int AData;
    HPALETTE APalette;
    ((TImage *)Component)->Picture->SaveToClipboardFormat(AFormat, AData, APalette);
    TClipboard *pClip = Clipboard(); // don't clear the clipboard!
    pClip->SetAsHandle(AFormat, AData);
}