The problem was that when I first configured the QReport, the database field was MEMO and not GRAPHIC. This information is stored in the .QR2 report file. And even though I corrected this field in the database using Database Manager, it would not be updated in the QuickReport.
The solution was to remove the dataset and add it again. This time the field correctly showed up as GRAPHIC, and the image showed up beautifully :-)
One possible solution could be to only remove the field in the dataset and then add it again.
The initial code for getting in image into the DB was:
Although this works fine, the image file has to be available on the disk when the program runs. A better solution is to get the images included in the .exe as an embedded resource. The simplest way to achieve this was to include a TImageList on a form, and populate this with the images I needed. Then use the following code to put them in the database:
The initial code for getting in image into the DB was:
(FieldByName('Icon') as TGraphicField).LoadFromFile('\path\to\image.bmp');
Although this works fine, the image file has to be available on the disk when the program runs. A better solution is to get the images included in the .exe as an embedded resource. The simplest way to achieve this was to include a TImageList on a form, and populate this with the images I needed. Then use the following code to put them in the database:
procedure InsertImageToDB(Field: TField; ImageIndex: Integer);
var
stream: TStream;
bmp: TBitmap;
begin
bmp := TBitmap.Create();
stream := Field.DataSet.CreateBlobStream(Field, bmWrite);
try
Frm.ImageList.GetBitmap(ImageIndex, bmp);
bmp.SaveToStream(stream);
finally
stream.Free;
bmp.Free;
end;
end;
This has to be included in a Edit()...Post() block to get it posted to the DB.
Ingen kommentarer:
Legg inn en kommentar