RAD Studio |  |

Adding Clipboard Formats

By default, when a user chooses Copy while a component is selected in the IDE, the component is copied in Delphi's 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.

Copy Code

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

Copy Code

    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);
    }

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!