Delphi Database, Delphi Components from ComponentAce
Products Download Order Contact us
Accessing BLOB Fields
Previous  Top  Next



Absolute Database supports BLOB (Binary Large OBject) fields which could be used to store large texts, RTF files, images and other binary data.

BLOB fields could be accessed via DB-aware controls, such as TDBMemo, TDBRichEdit, TDBImage and etc.
However sometimes direct access to the BLOB field value is required.
To access BLOB field value directly, you can use the
TABSBlobStream or TStream object.

The following example illustrates the reading of the BLOB field value and saving it to the file:

procedure TForm1.btSaveClick(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
  FileStream := TFileStream.Create('Comments.txt'
,fmCreate);
  BlobStream := ABSTable1.CreateBlobStream(ABSTable1.FieldByName('Comments'
),bmRead);
  FileStream.CopyFrom(BlobStream,BlobStream.Size);
  BlobStream.Free;
  FileStream.Free;
end;


The next example shows the update of the BLOB field value by storing the text loaded from the 'comments.txt' file:

procedure TForm1.btLoadClick(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TABSBlobStream;
begin
  ABSTable1.Edit;
  try
    FileStream := TFileStream.Create('Comments.txt'
,fmOpenRead or fmShareDenyNone);
    BlobStream := TABSBlobStream(ABSTable1.CreateBlobStream(ABSTable1.FieldByName('Comments'
),bmWrite));
    BlobStream.CopyFrom(FileStream,FileStream.Size);
    FileStream.Free;
    BlobStream.Free;
    ABSTable1.Post;
  except
    ABSTable1.Cancel;
    raise;
  end;
end;



        © 2003 - 2017 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Oct 22, 2017