还是BLob的问题,望指教(100分)

  • 主题发起人 主题发起人 sxj0704
  • 开始时间 开始时间
S

sxj0704

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
procedure TBlobForm.Button1Click(Sender: TObject);
var
FS: TFileStream;
//T:TBlobField;
begin
//T:=TBlobField.Create(self);
//ADODatasetImage.DataSet :=ADODataset1;
//end;
begin
//T:=TBlobField.Create(TBlobField(adodataset1.FieldByName('BLOBFILE')),bmWrite);
if opendialog1.execute then
begin
image1.picture.loadfromfile(opendialog1.filename);
if not (ADODataset1.State in [dsInsert, dsEdit]) then
ADODataset1.Edit;
ADODataset1.Insert ;
FS := TFileStream.Create(opendialog1.FileName , fmOpenRead);
try
//T.Clear ;
// T.DataSet :=ADODataset1;
ADODataset1.LoadFromFile(FS); //ADODatasetImages是一个TBlobField
finally
Free;
end;
ADODataset1.Post ;
end;
end;

end;


end.
运行时显示“FS和ADODataset.LoadFromFile的字符串格式不一致”,抱错
Listen to you
 
uses
procedure TBlobForm.Button1Click(Sender: TObject);
var
FS: TFileStream;
begin
if opendialog1.execute then
begin
image1.picture.loadfromfile(opendialog1.filename);
//下面这句话好象有问题 自己解决吧
if not (ADODataset1.State in [dsInsert, dsEdit]) then
ADODataset1.Edit;
ADODataset1.Insert ;
FS := TFileStream.Create(opendialog1.FileName , fmOpenRead);
try
//ADODataset1.LoadFromFile(FS); //ADODatasetImages是一个TBlobField
// 上面改为:
TBlobField(ADODataset1.FieldByName(ADODatasetImages)).LoadFromStream(FS);
finally
Free;
end;
ADODataset1.Post ;
end;
end;

end;

 
同意上面
 
改成 TmemoryStream
 
图象的话,直接用 adoblobstream
 
uses
procedure TBlobForm.Button1Click(Sender: TObject);
var
FS: TmemoryStream;
begin
if opendialog1.execute then
begin
image1.picture.loadfromfile(opendialog1.filename);
FS := TTmemoryStream.Create;
image1.picture.savetostream(fs);
fs.position:=0;
if not (ADODataset1.State in [dsInsert, dsEdit]) then
ADODataset1.Edit;
ADODataset1.Insert ;
Try
TBlobField(ADODataset1.FieldByName(ADODatasetImages)).LoadFromStream(FS);
finally
fs.Free;
end;
ADODataset1.Post ;
end;
end;

end;

 
后退
顶部