Mirror

How to store OLE objects in a blob field (Views: 100)


Problem/Question/Abstract:

How would I store an OLE object into a database's blob field and preferably be able to read it back in a usable form later on?

Answer:

To write a TOLEContainer to a blobfield:

var
  Stream: TBlobStream;
begin
  Stream := TBlobStream.Create(myOleField, bmWrite);
  try
    Ole1.SaveToStream(Stream);
  finally
    Stream.Free;
  end;
end;

To read it back:

var
  Stream: TBlobStream;
begin
  Stream := TBlobStream.Create(BugData.NotesNote, bmRead);
  try
    Ole1.LoadFromStream(Stream);
    Ole1.Iconic := False;
  finally
    Stream.Free;
  end;
end;

Where you put the code is up to you, but the DataChange and UpdateData events of the appropriate TDatasource might be a good idea.

<< Back to main page