procedure TForm1.Button1Click(Sender: TObject);
var
  stream:TMemorystream;
begin
  query1.CacheBlobs:=false;
  query1.SQL.Text:='select * from arc_guide1,guide_photo where arc_guide1.身份证号=guide_photo.Id';
  query1.Open;
//  query1.Last;
//  query1.First;
  application.ProcessMessages;
  showmessage(inttostr(query1.RecordCount));
  stream:=Tmemorystream.Create();
  TblobField(query1.FieldByName('Photo')).SaveToStream(stream);
  showmessage(inttostr(stream.Size));
  showmessage('asf');
end;如果执行如上代码, 显示的记录数为-1,别的都没有问题.
如果把
  query1.Last;
  query1.First;
两行加上,记录显示正确,但:
  TblobField(query1.FieldByName('Photo')).SaveToStream(stream);
执行出错. 这是为什么,是不是delphi的一个BUG???

解决方案 »

  1.   

    建议在sql语句中加上order by 子句
      

  2.   

    query1.SQL.Text:='select count(*) from arc_guide1,guide_photo where arc_guide1.身份证号=guide_photo.Id';
      

  3.   

    mrfanghansheng(☆☆☆木鱼☆☆☆) :加上也不行.不过还是谢谢你.
      

  4.   

    流的问题到是没想出来,但如果你想有条件连接两表,最好不要写成这样
    'select * from arc_guide1,guide_photo where arc_guide1.身份证号=guide_photo.Id'
    这样出来的是笛卡尔矢量积,有冗余,可写成
    'select * from arc_guide1 inner join guide_photo on arc_guide1.身份证号=guide_photo.Id'
      

  5.   

    first是必须加的~很正常不加出错~至于
    TblobField(query1.FieldByName('Photo')).SaveToStream(stream);
    出错,你就看看相关帮助了~
      

  6.   

    TblobField(query1.FieldByName('Photo')).SaveToStream(stream);
    改成
    (query1.FieldByName('Photo') as TblobField).SaveToStream(stream);试试
      

  7.   

    使用RecordCount属性的时候,请阅读Delphi提供的帮助。建议你先阅读Delphi的帮助,这比任何一个人的解释都准确!
      

  8.   

    Use RecordCount with care, because record counting can be a costly operation, especially for SQL queries that return large result sets. Generally, an application should only use RecordCount with Paradox and dBASE tables.
      

  9.   

    RecordCount并不是什么时候都有效的,还没弄明白就说是bug
    bug也太多了吧
    好好学学吧