Clipboard
Predefined types
TPredefinedClipboardFormat | MIME type |
---|---|
pcfText | text/plain |
pcfBitmap | image/bmp |
pcfPixmap | image/xpm |
pcfIcon | image/lcl.icon |
pcfPicture | image/lcl.picture |
pcfObject | application/lcl.object |
pcfComponent | application/lcl.component |
pcfCustomData | application/lcl.customdata |
pcfDelphiText | text/plain |
pcfDelphiBitmap | text/delphi.bitmap |
pcfDelphiPicture | Delphi picture |
pcfDelphiMetaFilePict | image/delphimetafilepict |
pcfDelphiObject | application/delphi.object |
pcfDelphiComponent | Delphi component |
pcfKylixPicture | image/delphi.picture |
pcfKylixBitmap | image/delphi.bitmap |
pcfKylixDrawing | image/delphi.drawing |
pcfKylixComponent | application/delphi.component |
Text
For use of simple text Clipboard offer property AsText which can be used for reading an writing plain text.
Writing text: <delphi>Clipboard.AsText := 'Hello clipboard!';</delphi>
Reading text: <delphi>ShowMessage('Clipboard content: ' + Clipboard.AsText);</delphi>
Text oriented components
Some visual components like TEdit, TMemo, TStringGrid, TLabeledEdit, TMaskEdit, TSpinEdit and TFloatSpinEdit have ability to select a part of contained text and offer additional functionality for handling clipboard operations on selected text.
<delphi> procedure CopyToClipboard;
procedure CutToClipboard; procedure PasteFromClipboard;</delpi>
HTML source
<delphi>uses
Clipbrd, ...;
procedure InsertHTMLSourceFromClipboard(Strings: TString); var
Fid: TClipboardFormat Str: WideString; Stream: TMemoryStream;
begin
Fid := Clipboard.FindFormatID('text/html'); if Fid <> 0 then try Stream := TMemoryStream.Create; if Clipboard.GetFormat(Fid, Stream) then begin Stream.Position := 0; Str := PWideChar(Stream.Memory); Str[(Stream.Size div 2) + 1] := #0; Strings.Text := UTF8Encode(Str); end; finally Stream.Free; end;
end;</delphi>
Image
Load from clipboard
<delphi>uses
Clipbrd, LCLIntf, LCLType, ...;
procedure LoadBitmapFromClipboard(Bitmap: TBitmap); begin
if Clipboard.HasFormat(PredefinedClipboardFormat(pcfDelphiBitmap)) then Bitmap.LoadFromClipboardFormat(PredefinedClipboardFormat(pcfDelphiBitmap)); if Clipboard.HasFormat(PredefinedClipboardFormat(pcfBitmap)) then Bitmap.LoadFromClipboardFormat(PredefinedClipboardFormat(pcfBitmap));
end;</delphi>
Save to clipboard
<delphi>uses
Clipbrd, ...;
procedure SaveBitmapToClipboard(Bitmap: TBitmap); begin
Clipboard.Assign(Bitmap);
end;</delphi>