Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blob field to picture

Status
Not open for further replies.

hryundel

Programmer
Feb 3, 2004
3
RU
HI,
How can I save word document from Blob-field in data base MS Access to file in the graphical format (.bmp for examole)? I use Delphi 7.
Thanks beforehand.
 
Hello,

Here are two functions that copy to and from blob fields in delphi...

You will need to pass a valid field object and a full file path. Hopefully should point you in the right direction.


procedure TfrmSQLDocAdmin.SaveToSQL(AField: TField; AFile: TFileName);
var
bs : TStream;
fs : TFileStream;
strFileExt : string;
strFilePath : string;
strFileName : string;

begin

ADOTDocument.Insert;
AField.DataSet.Edit;

bs := AField.DataSet.CreateBlobStream(AField,bmWrite);
try
bs.Seek(0,soFromBeginning);
fs := TFileStream.Create(AFile,fmOpenRead);
try
bs.CopyFrom(fs,fs.Size);
finally
fs.Free
end;
finally
bs.Free
end;
strFileExt := ExtractFileExt(AFile);
strFilePath := ExtractFilePath(AFile);
strFileName := ExtractFileName(AFile);

with ADOTDocument do
begin
FieldByName('OrigDocName').Value := strFileName;
FieldByName('OrigDocPath').Value := strFilePath;
FieldByName('FileExt').Value := strFileExt;
Post;
end;

ShowMessage('Done');
end;

procedure TfrmSQLDocAdmin.LoadFromSQL(AField: TField; AFile: TFileName);
var
bs : TStream;
fs : TFileStream;

begin
bs := AField.DataSet.CreateBlobStream(AField,bmRead);
try
bs.Seek(0,soFromBeginning);
fs := TFileStream.Create(AFile,fmCreate);
try
fs.CopyFrom(bs,bs.Size);
finally
fs.Free
end;
finally
bs.Free
end;

ShowMessage('Done');

end;


There are two ways to write error-free programs; only the third one works.
 
Just to expand a bit, you will need to hack these about as they copy the file paths etc to the Database, but should give you the important bits...



There are two ways to write error-free programs; only the third one works.
 
The main question in that how transform format OLE of object in Access to that which then Windows can to open. Where to esteem about it, give the reference.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top