Копирование потока компонент в буфер обмена |
Previous Top Next |
Code: |
{ Clipboard has methods GetComponent and SetComponent but we need to stream multiple components to the clipboard to include copy paste type of feature.
}
procedure CopyStreamToClipboard(fmt: Cardinal; S: TStream); var hMem: THandle; pMem: Pointer; begin S.Position := 0; hMem := GlobalAlloc(GHND or GMEM_DDESHARE, S.Size); if hMem <> 0 then begin pMem := GlobalLock(hMem); if pMem <> nil then begin S.Read(pMem^, S.Size); S.Position := 0; GlobalUnlock(hMem); Clipboard.Open; try Clipboard.SetAsHandle(fmt, hMem); finally Clipboard.Close; end; end { If } else begin GlobalFree(hMem); OutOfMemoryError; end; end { If } else OutOfMemoryError; end; { CopyStreamToClipboard } |
Code: |
procedure CopyStreamFromClipboard(fmt: Cardinal; S: TStream); var hMem: THandle; pMem: Pointer; begin hMem := Clipboard.GetAsHandle(fmt); if hMem <> 0 then begin pMem := GlobalLock(hMem); if pMem <> nil then begin S.Write(pMem^, GlobalSize(hMem)); S.Position := 0; GlobalUnlock(hMem); end { If } else raise Exception.Create('CopyStreamFromClipboard: could not lock global handle ' + 'obtained from clipboard!'); end; { If } end; { CopyStreamFromClipboard } |
©Drkb::01889
Взято с сайта: http://www.swissdelphicenter.ch