查遍网络,也没有答案的新问题,同志们帮个忙吧! ( 积分: 100 )

  • 主题发起人 主题发起人 zwz_good
  • 开始时间 开始时间
Z

zwz_good

Unregistered / Unconfirmed
GUEST, unregistred user!
问题描述:<br> &nbsp; &nbsp;希望将word中的内容通过剪贴板和流存储,保存到数据库中。<br> &nbsp; &nbsp;当保存带有bmp格式的图片时,出现错误。<br> &nbsp; 比如:1、保存第一条记录时存在图片1,保存成功。<br> &nbsp; &nbsp; &nbsp; &nbsp; 2、再保存第二条记录存在图片2,保存成功。<br> &nbsp; &nbsp; &nbsp; &nbsp; 3、当调用第一条记录时图片1已由图片2取代.<br>为啥??各路高手出招吧!!
 
问题描述:<br> &nbsp; &nbsp;希望将word中的内容通过剪贴板和流存储,保存到数据库中。<br> &nbsp; &nbsp;当保存带有bmp格式的图片时,出现错误。<br> &nbsp; 比如:1、保存第一条记录时存在图片1,保存成功。<br> &nbsp; &nbsp; &nbsp; &nbsp; 2、再保存第二条记录存在图片2,保存成功。<br> &nbsp; &nbsp; &nbsp; &nbsp; 3、当调用第一条记录时图片1已由图片2取代.<br>为啥??各路高手出招吧!!
 
可能跟Bitmap的赋值有关,因其为对象,不能使用“:=”进行赋值,而要用Assign,你将这段代码贴上来大家看看啊!
 
to coolqiang, <br> &nbsp; 利用剪贴板,将Word中的文字与图片保存到流中,之后再从流中存入数据库。这个过程<br>用不到Bitmap对象的赋值,就是把剪贴板中的信息看成了二进制存的。
 
老兄,可以把代码贴出来么,估计是插入时出了问题。
 
贴出来会很长。<br>unit ClipStream;//此单元来自Zswang//wjhu111@21cn.com<br>interface<br>uses Classes, Windows, clipbrd, Ut9Debug;<br>type<br> &nbsp;TDataIdnet = array[0..2] of Char;<br> &nbsp;TClipboardFileHead = packed record<br> &nbsp; &nbsp;rIdent: TDataIdnet;<br> &nbsp; &nbsp;rCount: Word;<br> &nbsp;end;<br> &nbsp;TClipboardFileItem = packed record<br> &nbsp; &nbsp;rFormat: Word;<br> &nbsp; &nbsp;rSize: Longword;<br> &nbsp; &nbsp;rData: Pointer;<br> &nbsp;end;<br>const<br> &nbsp;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> &nbsp;vClipboardFileHead: TClipboardFileHead;<br> &nbsp;vClipboardFileItem: TClipboardFileItem;<br> &nbsp;I: Integer;<br> &nbsp;vData: THandle;<br>begin<br> &nbsp;Result := False;<br> &nbsp;if not Assigned(mStream) then<br> &nbsp; &nbsp;Exit;<br> &nbsp;vClipboardFileHead.rIdent := rDataIdnet;<br> &nbsp;vClipboardFileHead.rCount := Clipboard.FormatCount;<br> mStream.Write(vClipboardFileHead, SizeOf(vClipboardFileHead));<br> try<br> &nbsp; &nbsp;Clipboard.Open;<br> &nbsp; &nbsp;for I := 0 to Clipboard.FormatCount - 1 do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;vData := GetClipboardData(Clipboard.Formats);<br> &nbsp; &nbsp; &nbsp;vClipboardFileItem.rFormat := Clipboard.Formats;<br> &nbsp; &nbsp; &nbsp;vClipboardFileItem.rSize := GlobalSize(vData);<br> &nbsp; &nbsp; &nbsp;vClipboardFileItem.rData := GlobalLock(vData);<br> &nbsp; &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp;mStream.Write(vClipboardFileItem, SizeOf(vClipboardFileItem) -<br> &nbsp; &nbsp; &nbsp; &nbsp;SizeOf(vClipboardFileItem.rData));<br> &nbsp; &nbsp; &nbsp; &nbsp;mStream.Write(vClipboardFileItem.rData^, vClipboardFileItem.rSize);<br> &nbsp; &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp; &nbsp;GlobalUnlock(vData);<br> &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;Clipboard.Close;<br> &nbsp;end;<br> &nbsp;Result := True;<br>end; { ClipboardSaveToStream }<br><br>function ClipboardLoadFromStream(mStream: TStream): Boolean;<br>var<br> &nbsp;vClipboardFileHead: TClipboardFileHead;<br> &nbsp;vClipboardFileItem: TClipboardFileItem;<br> &nbsp;I: Integer;<br> &nbsp;vData: THandle;<br>begin<br> &nbsp;Result := False;<br> &nbsp;if not Assigned(mStream) then<br> &nbsp; &nbsp;Exit;<br> &nbsp;if mStream.Size &lt;= SizeOf(vClipboardFileHead) then<br> &nbsp; &nbsp;Exit;<br> &nbsp;mStream.Read(vClipboardFileHead, SizeOf(vClipboardFileHead));<br> &nbsp;if vClipboardFileHead.rIdent &lt;&gt; rDataIdnet then<br> &nbsp; &nbsp;Exit;<br> &nbsp;Clipboard.Clear;<br> &nbsp;Clipboard.Open;<br> &nbsp;try<br> &nbsp; &nbsp;for I := 0 to vClipboardFileHead.rCount - 1 do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;mStream.Read(vClipboardFileItem, SizeOf(vClipboardFileItem) -<br> &nbsp; &nbsp; &nbsp; &nbsp;SizeOf(vClipboardFileItem.rData));<br> &nbsp; &nbsp; &nbsp;vData := GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE,<br> &nbsp; &nbsp; &nbsp; &nbsp;vClipboardFileItem.rSize);<br> &nbsp; &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp;vClipboardFileItem.rData := GlobalLock(vData);<br> &nbsp; &nbsp; &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mStream.Read(vClipboardFileItem.rData^, vClipboardFileItem.rSize);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetClipboardData(vClipboardFileItem.rFormat, vData);<br> &nbsp; &nbsp; &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GlobalUnlock(vData);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp; &nbsp;GlobalFree(vData);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;Clipboard.Close;<br> &nbsp;end;<br> &nbsp;Result := True;<br>end; { ClipboardLoadFromStream }<br>其中ClipboardSaveToStream为由剪贴板到流中<br>而ClipboardLoadFromStream为流到剪贴板中<br>数据库保存就不贴了,这两个函数是问题的关键
 
我只是想,是不是你的剪贴板和流的问题,用过是不是清空,或是释放,然后重新create,我用的时候一般是将不同的用两个流来做,这样谁也不影响谁
 
to aricyoung,<br>估计就是剪贴板和流问题,每次用到流时都是重新创建的,用后就释放,如下<br> &nbsp;ms:= TMemoryStream.Create;<br> &nbsp;try<br> &nbsp; &nbsp;if ClipSaveToStream(ms) then<br> &nbsp; &nbsp;begin<br> &nbsp; //'添加数据!<br> &nbsp; &nbsp;DataModule5.ADOQuery1.Append;<br> &nbsp; &nbsp;TBlobField(DataModule5.ADOQuery1.FieldByName('Content')).LoadFromStream(ms);<br> &nbsp; &nbsp;DataModule5.ADOQuery1.Post;<br> &nbsp; &nbsp;Clipboard.Clear;<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;Application.MessageBox('流存储有误!','错误提示',MB_OK+MB_ICONINFORMATION);<br> &nbsp;finally<br> &nbsp; &nbsp;ms.Free;<br> &nbsp;end;
 
fstream:=tmemorystream.Create;<br> &nbsp; &nbsp; &nbsp;... .SaveToStream(fstream);<br> &nbsp; &nbsp; &nbsp; fstream.Position:=0; &nbsp;<br>....<br>....<br>LoadFromStream(fstream); <br>看看
 
to gameboyda<br> &nbsp;试过,还是不行[:(]
 
自己顶一下
 
给个理由吧,同志们[:(]
 
唉,此问题无解
 
没人会,失望,唉!<br>结帐 &nbsp;分配不均,见谅!
 
后退
顶部