TClientDataSet如何存取Image(bmp文件)字段,请给详细解答。(200分)

  • 主题发起人 主题发起人 zyhhly
  • 开始时间 开始时间
Z

zyhhly

Unregistered / Unconfirmed
GUEST, unregistred user!
TClientDataSet如何存取Image(bmp文件)字段,请给详细解答。本人试过多次都无法成功存取。
 
TBlobField(cds.FieldByName('****')).LoadFromStream……
TBlobField(cds.FieldByName('****')).SaveToStream……
 
注意:本人使用的有Pooler连接数据库的。
 
如果你用的是MIDAS 机制,哪么 DataSetProvider1.Options .[poFetchBlobsOnDemand] 要加上
 
同意楼上的
 
var
m: TmemoryStream;
begin
m:= tmemoryStream.create();
tblobfield(clientdataset1.fieldbyname('[字段名]')).savetostream(m);
Timage1.picture.graphic.loadfromstream(m);
....
end;
 
Use LoadFromStream to copy the contents of a stream into the BLOB field. Specify the stream from which the field抯 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抯 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;
if ((ClientDataSet1->State != dsInsert) &&
(ClientDataSet1->State != dsEdit))
ClientDataSet1->Insert();
TMemoryStream *pMS = new TMemoryStream;
try
{
Image1->Picture->Bitmap->SaveToStream(pMS);
ClientDataSet1Images->LoadFromStream(pMS);
}
__finally
{
delete pMS;
}
ClientDataSet1->Post();
 
后退
顶部