Здравствуйте, Andrey01, Вы писали:
A>Как корректно использовать поле blob для заполнения его данными ? (Delphi)
A>К примеру как загруженное изображение сохранить в поле blob, а затем отобразить его в программе (через TImage?). (изображение не обязательно будет bmp, может быть и jpg, gif, pcx и т.д.)
A>это поле blob должно потом считывается из php-скрипта. mysql
RTFM:
TBlobField.SaveToStream
Saves the contents of the BLOB field to a stream.
procedure SaveToStream(Stream: TStream);
Description
Use SaveToStream to copy the contents of a BLOB field to a stream. Specify the name of the stream to which the field’
s value is saved as the value of the Stream parameter.
Note: The Stream parameter is typically not a BLOB stream. BLOB streams (returned by the dataset’s CreateBlobStream method) provide a completely separate mechanism for streaming data from a BLOB field.
var
MS: TMemoryStream;
begin
MS := TMemoryStream.Create;
try
SQLDataSet1Images.SaveToStream(MS);
Image1.Picture.Bitmap.LoadFromStream(MS);
finally
MS.Free;
end;
end;
TBlobField.LoadFromStream
Loads BLOB data from a stream into the field.
procedure LoadFromStream(Stream: TStream);
Description
Use LoadFromStream to copy the contents of a stream into the BLOB field. Specify the stream from which the field’s value is copied as the value of the Stream parameter.
Note: The Stream parameter is typically not a BLOB stream. BLOB streams (returned by the dataset’s CreateBlobStream method) provide a completely separate mechanism for streaming data into a BLOB field.
var
MS: TMemoryStream;
begin
if not (ClientDataSet1.State in [dsInsert, dsEdit]) then
ClientDataSet1.Insert;
MS := TMemoryStream.Create();
try
Image1.Picture.Bitmap.SaveToStream(MS);
ClientDataSet1Images.LoadFromStream(MS);
finally
MS.Free;
end;
ClientDataSet1.Post;
end;
TDataSet.CreateBlobStream + смотри соответствующий экзампл.
Provides the interface for a method that creates a blob stream for a Binary large object (BLOB) field in the dataset.
function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; virtual;
Description
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. 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.
... << RSDN@Home 1.0 beta 6a silent>>