Q
qutwah
Unregistered / Unconfirmed
GUEST, unregistred user!
我在全文检索中看到如下代码,但在我机器上不能执行.每次执行CopyStreamFromClipboard时,都产生异常(raise Exception.Create( 'CopyStreamFromClipboard: could not lock global handle '+ 'obtained from clipboard!'),不知是什么原因,各位高手能帮忙看看吗?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 } 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 }