RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDataSet.CreateBlobStream Method

Provides the interface for a method that creates a blob stream for a Binary large object (BLOB) field in the dataset.

Pascal
function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; virtual;
C++
virtual __fastcall TStream CreateBlobStream(TField Field, TBlobStreamMode Mode);

Call CreateBlobStream to obtain a stream for reading and writing the value of the field specified by the Field parameter. The Mode parameter indicates whether the stream will be used for reading the field's value (bmRead), writing the field's value (bmWrite), or modifying the field's value (bmReadWrite). 

Blob streams are created in a specific mode for a specific field on a specific record. Applications create a new blob stream every time the record in the dataset changes: do not reuse an existing blob stream.  

As implemented in TDataSet, CreateBlobStream always returns nil (Delphi) or NULL (C++). Descendants of TDataSet override this method to create the TStream descendant that reads and writes BLOB data in the format that dataset type uses to store BLOB fields.

Tip: It is preferable to call CreateBlobStream rather than creating a blob stream directly in code. This ensures that the stream is appropriate to the dataset, and may also ensure that datasets that do not always store BLOB data in memory fetch the blob data before creating the stream.
 

C++ Examples: 

 

/*
The following example copies the data in the Notes field of
Table1 or SQLDataSet1 to the Remarks field of ClientDataSet1.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TBlobType blobType = Table1Notes->BlobType;
  TStream *Stream1 = new TBlobStream(Table1Notes, bmRead);
  try
  {
    CDS2->Edit();
    // here’s a different way to create a blob stream }
    TStream *Stream2 = CDS2->CreateBlobStream(CDS2->FieldByName("Remarks"), bmReadWrite);
    try
    {
      Stream2->CopyFrom(Stream1, Stream1->Size);
//    CDS2.Post;
//    CDS2.Active := True;
    }
    __finally
    {
      delete Stream2;
    }
  }
  __finally
  {
    delete Stream1;
  }
};

 

Delphi Examples: 

{
The following example copies the data in the Notes field of
Table1 or SQLDataSet1 to the Remarks field of ClientDataSet1.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  Stream1: TBlobStream;
  Stream2: TStream;
  blobType : TBlobType;
begin
  blobType := Table1Notes.BlobType;
  Stream1 := TBlobStream.Create(Table1Notes, bmRead);
  try
    CDS2.Edit;
    { here’s a different way to create a blob stream }
    Stream2 := CDS2.CreateBlobStream(CDS2.FieldByName('Remarks'), bmReadWrite);
    try
      Stream2.CopyFrom(Stream1, Stream1.Size);
//    CDS2.Post;
//    CDS2.Active := True;
    finally
      Stream2.Free;
    end;
  finally
    Stream1.Free;
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!