memo1为什么读不到Stream?

horselily 2012-12-12 03:13:11
代码如下:

var mstr:TMemoryStream;
begin
mstr:=TMemoryStream.Create;
mstr:=getkqinfo;

memo1.Lines.LoadFromStream(mstr);
end;

function getkqinfo:TMemoryStream;
var mstr:TMemoryStream;
begin
mstr:=TMemorySTream.Create;
with Adoqry2 do
begin
Active := True;
if not IsEmpty then
begin
TBlobField(FieldByName('kqinfo')).SaveToStream(mstr);
end;
end;
result := mstr;
end;

请大家帮忙看下,为什么memo1取不到数,我测试了的,返回来的mstr size大小超过20000。
...全文
154 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
horselily 2012-12-12
  • 打赏
  • 举报
回复
引用 4 楼 simonhehe 的回复:
引用 2 楼 horselily 的回复:这个我可以肯定的是mstr是取到数了,但memo1就是读不了这个mstr 上边的例子演示了stream读取 如果你确定mstr不为nil, 执行下 mstr.Position := 0;
是的,设了position := 0 就好了。
simonhehe 2012-12-12
  • 打赏
  • 举报
回复
引用 2 楼 horselily 的回复:
这个我可以肯定的是mstr是取到数了,但memo1就是读不了这个mstr
上边的例子演示了stream读取 如果你确定mstr不为nil, 执行下 mstr.Position := 0;
simonhehe 2012-12-12
  • 打赏
  • 举报
回复
function getkqinfo:TMemoryStream;
begin
  Result := TMemorySTream.Create;
  Result.LoadFromFile('c:\sql.txt');
  Result.Position := 0;
end;

procedure TForm11.btn1Click(Sender: TObject);
begin
  mmo1.Lines.LoadFromStream(getkqinfo);
end;
horselily 2012-12-12
  • 打赏
  • 举报
回复
这个我可以肯定的是mstr是取到数了,但memo1就是读不了这个mstr
feiba7288 2012-12-12
  • 打赏
  • 举报
回复
试下这样:

var mstr:TMemoryStream;
begin
  mstr:=TMemoryStream.Create;
  if getkqinfo(mstr) then
    memo1.Lines.LoadFromStream(mstr);
  mstr.Free;
end;

function getkqinfo(mstr: TMemoryStream): Boolean;
begin
  with Adoqry2 do
  begin
    Active := True;
    if not IsEmpty then
    begin
      TBlobField(FieldByName('kqinfo')).SaveToStream(mstr);
      result := True;
    end
    else result := False;
  end;
end;

16,743

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧