 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Julien Ferraro Guest
|
Posted: Thu Sep 25, 2003 11:52 am Post subject: How to store and retrieve Bitmap in a Firebird Database |
|
|
Hi all,
I do database apps for years now and can you imagine, it's the first time i
need to store a picture in a table... I thought that there is some kind of
TField.AsBitmap property, but no ...
SO what is the best way to assign a TPicture (or a TBitmap, depends on
what is best) to a TField in order to write it to the database ? In the
same way, how to read from the TField (assign the content of the Tfield
retrieved from the database to my TBitmap) ?
Thank you
Julien
|
|
| Back to top |
|
 |
Heiko Luettge Guest
|
Posted: Thu Sep 25, 2003 7:22 pm Post subject: Re: How to store and retrieve Bitmap in a Firebird Database |
|
|
source from me
saving
------
with FQuerySQL do
begin
SQL.Clear;
SQL.Add('Insert Into LL_Reports ');
SQL.Add('(Id,ReportName,Description,ReportType,ReportData) Values
');
SQL.Add('(:Id,:ReportName,:Description,:ReportType,:ReportData)');
ParamByName('Id').AsInteger:= lNewDBId;
ParamByName('ReportName').AsString:= theDBReportItem.sReportName;
ParamByName('Description').AsString:= theDBReportItem.sDescription;
ParamByName('ReportType').AsInteger:=
ReportType2Integer(theDBReportItem.ReportType);
ParamByName('ReportData').LoadFromFile(theFileName, ftBlob);
ExecSQL;
theFileName is the name of the bitmap
loading
--------
function TDBReportClass.LoadReportIntoFile(theDBReportItem: TDBReportItem;
const theFileName: String; var theErrorStr: String): Boolean;
var
BlobStr : TStream;
FileStream : TFileStream;
begin
Result:= False;
theErrorStr:= S_internal_error;
try
with FQuerySQL do
begin
SQL.Clear;
SQL.Add('Select * from LL_Reports Where Id=:Id');
ParamByname('Id').AsInteger:= theDBReportItem.lDBId;
Open;
try
if QueryIsNotEmpty(FQuerySQL) then
begin
{ die Daten des Reports brauch ich viell. auch mal }
Fields2Data(FQuerySQL, theDBReportItem, theErrorStr);
blobstr:= FQuerySQL.CreateBlobStream(
FQuerySQL.FieldByName('ReportData'),bmRead);
FileStream:= TFileStream.Create(theFileName,fmCreate);
FileStream.CopyFrom(BlobStr,0);
FileStream.Free;
blobstr.Free;
{ Status-Variablen des Business-Objects setzen }
theDBReportItem.bIsNew := False;
theDBReportItem.bIsChanged := False;
Result:= True;
Heiko
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|