25 December 2010

Lazarus, PostgreSQL, Fortes report - Bytea String BLOB fields

To save some image into dbimage control on a form :

procedure T_form._dbimageDblClick(Sender: TObject);
begin
if _opendialog.Execute then
begin
_db_grid.DataSource.DataSet.Edit;
_dbimage.Picture.LoadFromFile(_opendialog.FileName) ;
end;
end;

To print those fields in Fortes report, use dbimage >

procedure T_report._rlimageBeforePrint(Sender: TObject; var PrintIt: boolean);
var
st : Tstream;
s : string;
gc : TGraphicClass;
AGraphic : TGraphic;

begin
gc := nil;
AGraphic := nil;

st := _datamodule._table.CreateBlobStream(_datamodule._table_image_field,bmRead);
s := st.ReadAnsiString;

try
gc := GetGraphicClassForFileExtension(s);
if assigned(gc) then // gc is never assigned
begin
AGraphic := gc.Create; // never executed
AGraphic.LoadFromStream(st); // never executed
_rlimage.Picture.Assign(AGraphic); // never executed
end;
finally
if assigned(AGraphic) then
AGraphic.Free;
st.Free;
end
end;

I spend whole day just to develop those code ...

No comments: