OleContainer怎么连接Access数据库的ole字段

字体大小: 中小 标准 ->行高大小: 标准
//从数据库读取OLE字段到OleContainer控件
procedure TfrmResPaper.dgMainDblClick(Sender: TObject);
var
    Query:TADOQuery;
    Stream:TADOBlobStream;
begin
  inherited;
  if not ((DMResPaper.State=dsBrowse) and (DMResPaper.RecordCount>0))  then Exit;

  dgMain.Enabled:=False;
  Panel1.Enabled:=False;
  Query:=TADOQuery.Create(nil);
  with Query do
  begin
      Connection:=Pubconn;
      SQL.Clear;
      SQL.Add('SELECT ID,RES_NO,PAPER FROM B_PAPER WHERE ID='''+DMResPaper.FieldByName('ID').AsString+''''
              +' AND RES_NO='''+DMResPaper.FieldByName('RES_NO').AsString+''' AND PAPER IS NOT NULL');
      Open;
      if RecordCount=0 then
          OlePaper.DestroyObject
      else
      begin
          Stream:=TADOBlobStream.Create(TBlobField(FieldByName('PAPER')),bmRead);
          try
              OlePaper.LoadFromStream(Stream);
          finally
              Stream.Free;
          end;
      end;
      Query.Free;
  end;
  dgMain.Enabled:=True;
  Panel1.Enabled:=True;
  EpsDLG('图纸载入完毕。');
end;

//将Olecontainer中的内容保存到数据库中
procedure TfrmResPaper.bbnSavePaperClick(Sender: TObject);
var
    Query:TADOQuery;
    Stream:TADOBlobStream;
begin
    if not ((OlePaper.State=osLoaded) and
        (DMResPaper.State=dsBrowse) and (DMResPaper.RecordCount>0))  then Exit;
    Query:=TADOQuery.Create(nil);
    with Query do
    begin
        Connection:=Pubconn;
        SQL.Clear;
        SQL.Add('SELECT ID,RES_NO,PAPER FROM B_PAPER WHERE ID='''+DMResPaper.FieldByName('ID').AsString+''''
                +' AND RES_NO='''+DMResPaper.FieldByName('RES_NO').AsString+'''');
        Open;
        Edit;
        Stream:=TADOBlobStream.Create(TBlobField(FieldByName('PAPER')),bmReadWrite);
        try
            try
                OlePaper.SaveToStream(Stream);
            finally
                Stream.Free;
            end;
            Post;
            EpsDLG('图纸保存成功!');
        except
            EpsDLG('图纸保存失败!');
        end;
        Query.Free;
    end;

end;

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/67727.html