用ado 读取Access中数据类型为ole (长二进制blob)数据为乱码?请教(100分)

  • 主题发起人 主题发起人 diffbridge
  • 开始时间 开始时间
D

diffbridge

Unregistered / Unconfirmed
GUEST, unregistred user!
用ado &nbsp;读取Access中数据类型为ole &nbsp;(长二进制blob)数据为乱码?请教<br>我用好几种方式多是乱码<br>一。<br>var<br>&nbsp; Buffer: PChar;<br>&nbsp; MemSize: Integer;<br>&nbsp; Stream: TBlobStream;<br>begin<br>&nbsp; Stream := TBlobStream.Create(ADOTable1.FieldByName('zc') as TBlobField, bmRead);<br>&nbsp; try<br>&nbsp; &nbsp; MemSize := Stream.Size;<br>&nbsp; &nbsp; Inc(MemSize); {Make room for the buffer's null terminator.}<br>&nbsp; &nbsp; Buffer := AllocMem(MemSize); &nbsp; &nbsp; {Allocate the memory.}<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; Stream.Read(Buffer^, MemSize); {Read Notes field into buffer.}<br>&nbsp; &nbsp; &nbsp; Memo1.SetTextBuf(Buffer); &nbsp; &nbsp; &nbsp;{Display the buffer's contents.}<br><br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; FreeMem(Buffer, MemSize);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; Stream.Free;<br>&nbsp; end;<br>二<br>ms:=TmemoryStream.create();<br>TBlobField(ADOTable1.FieldByName('aa')).SaveToStream(ms);<br>ms0.position:=0;<br>memo1.Lines.LoadFromStream(ms)
 
请达人多多帮忙!
 
大虾们没有碰到过这样的问题吗
 
有些控制字符,比如回车、换行,或者是中文字符,它们从内存加载到memo显示的时候是会出现乱码的。解决的办法倒是有,你可以试试将内存中的文件复制到剪贴板对象(如:copytoclipoard,然后memo.pastefromclipoard),然后再粘贴到memo,操作系统会完成相应的转换。前提是你要显示的内容必须是文本,当然包括中文,否则会丢失数据(在memo中缺少原始数据的某些部分)。
 
不好意思,内存拷贝到剪贴板如何操作,如何这样,会不会导致速度慢,因为要清楚到剪贴板的内容。<br>请问还有其他办法吗
 
后退
顶部