这段代码可存所有格式的文件:
procedure TfmBlob.btnSaveClick(Sender: TObject);
var
FStream: TFileStream;
BStream: TBlobStream;
begin
if not OpenDialog1.Execute then exit;
FStream := TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
Table1.Edit;
BStream := TBlobStream.Create(Table1Doc,bmReadwrite);
with BStream do begin
Seek(0,soFromBeginning);
Truncate;
CopyFrom(FStream,FStream.Size)
end;
Table1.Post;
BStream.Free;
FStream.Free;
btnReadDoc.Enabled := false;
btnReadPic.Enabled := false;
end;
这是把字段作为文档读入时的操作:(Edit.text 指明文件名)
procedure TfmBlob.btnReadDocClick(Sender: TObject);
var
BStream: TBlobStream;
FStream: TFileStream;
begin
BStream := TBlobStream.Create(Table1Doc,bmRead);
FStream := TFileStream.Create('C:/' + Edit1.Text,fmCreate);
FStream.CopyFrom(BStream,BStream.Size);
BStream.Free;
FStream.Free;
OleContainer1.CreateObjectFromFile('C:/' + Edit1.Text,false)
end;
这是把字段内容做为位图读入的代码:
procedure TfmBlob.btnReadPicClick(Sender: TObject);
var
BStream: TStream;
begin
BStream := TBlobStream.Create(Table1Doc,bmRead);
Image1.Picture.Bitmap.LoadFromStream(Bstream);
BStream.Free;
end;