Difference between revisions of "Clipboard"
From Lazarus wiki
Jump to navigationJump to searchLine 42: | Line 42: | ||
==Text== | ==Text== | ||
+ | |||
+ | ==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== | ==Image== |
Revision as of 13:34, 27 January 2012
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
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>