贴出来会很长。<br>unit ClipStream;//此单元来自Zswang//wjhu111@21cn.com<br>interface<br>uses Classes, Windows, clipbrd, Ut9Debug;<br>type<br> TDataIdnet = array[0..2] of Char;<br> TClipboardFileHead = packed record<br> rIdent: TDataIdnet;<br> rCount: Word;<br> end;<br> TClipboardFileItem = packed record<br> rFormat: Word;<br> rSize: Longword;<br> rData: Pointer;<br> end;<br>const<br> rDataIdnet: TDataIdnet = 'cbf';<br>function ClipboardSaveToStream(mStream: TStream): Boolean;<br>function ClipboardLoadFromStream(mStream: TStream): Boolean;<br>implementation<br>function ClipboardSaveToStream(mStream: TStream): Boolean;<br>var<br> vClipboardFileHead: TClipboardFileHead;<br> vClipboardFileItem: TClipboardFileItem;<br> I: Integer;<br> vData: THandle;<br>begin<br> Result := False;<br> if not Assigned(mStream) then<br> Exit;<br> vClipboardFileHead.rIdent := rDataIdnet;<br> vClipboardFileHead.rCount := Clipboard.FormatCount;<br> mStream.Write(vClipboardFileHead, SizeOf(vClipboardFileHead));<br> try<br> Clipboard.Open;<br> for I := 0 to Clipboard.FormatCount - 1 do<br> begin<br> vData := GetClipboardData(Clipboard.Formats);<br> vClipboardFileItem.rFormat := Clipboard.Formats;<br> vClipboardFileItem.rSize := GlobalSize(vData);<br> vClipboardFileItem.rData := GlobalLock(vData);<br> try<br> mStream.Write(vClipboardFileItem, SizeOf(vClipboardFileItem) -<br> SizeOf(vClipboardFileItem.rData));<br> mStream.Write(vClipboardFileItem.rData^, vClipboardFileItem.rSize);<br> finally<br> GlobalUnlock(vData);<br> end;<br><br> end;<br> finally<br> Clipboard.Close;<br> end;<br> Result := True;<br>end; { ClipboardSaveToStream }<br><br>function ClipboardLoadFromStream(mStream: TStream): Boolean;<br>var<br> vClipboardFileHead: TClipboardFileHead;<br> vClipboardFileItem: TClipboardFileItem;<br> I: Integer;<br> vData: THandle;<br>begin<br> Result := False;<br> if not Assigned(mStream) then<br> Exit;<br> if mStream.Size <= SizeOf(vClipboardFileHead) then<br> Exit;<br> mStream.Read(vClipboardFileHead, SizeOf(vClipboardFileHead));<br> if vClipboardFileHead.rIdent <> rDataIdnet then<br> Exit;<br> Clipboard.Clear;<br> Clipboard.Open;<br> try<br> for I := 0 to vClipboardFileHead.rCount - 1 do<br> begin<br> mStream.Read(vClipboardFileItem, SizeOf(vClipboardFileItem) -<br> SizeOf(vClipboardFileItem.rData));<br> vData := GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE,<br> vClipboardFileItem.rSize);<br> try<br> vClipboardFileItem.rData := GlobalLock(vData);<br> try<br> mStream.Read(vClipboardFileItem.rData^, vClipboardFileItem.rSize);<br> SetClipboardData(vClipboardFileItem.rFormat, vData);<br> finally<br> GlobalUnlock(vData);<br> end;<br> except<br> GlobalFree(vData);<br> end;<br> end;<br> finally<br> Clipboard.Close;<br> end;<br> Result := True;<br>end; { ClipboardLoadFromStream }<br>其中ClipboardSaveToStream为由剪贴板到流中<br>而ClipboardLoadFromStream为流到剪贴板中<br>数据库保存就不贴了,这两个函数是问题的关键