on the form. I am using dataset to display results at TAdvSTringGRid (code is given below).
All other values are displaying perfectly except Image in database. Where it is expected to show image, it is showing junk characters.
How to display image perfectly from DataBase at TAdvStringGrid.?
Code: Select all
while not results.EOF do
begin
if (j>sg.rowcount) then
sg.rowcount := sg.rowcount + 1;
for i := 0 to results.fields.Count - 1 do
begin
if i=0 then
else if i = 4 then
//Here I want to display image from db
else
sg.cells[i,j] := results.FieldByName(names[i]).AsString;
end;
results.Next;
inc(j);
end;
Code: Select all
Grid.CreatePicture(2,3,True,Shrink,0,haLeft,vaTop).LoadFromFile(‘TST.JPG’);
procedure AddPicture(ACol,ARow: Integer;APicture:TPicture;transparent: Boolean; stretchmode:TStretchMode; padding: Integer; hal:TCellHalign; val:TCellValign);
function GetPicture(ACol,ARow: Integer): TPicture;
Grid.CreateFilePicture(2,3,True,Shrink,0,haLeft,vaTop).Filename := ‘TST.JPG’;
Code: Select all
function CreatePicture(ACol,ARow:Integer; transparent:Boolean; stretchmode:TStretchMode; padding:Integer; hal:TCellHalign; val:TCellValign):TPicture;
function AddPicture(ACol,ARow:Integer; aPicture:TPicture; transparent:Boolean; stretchmode:TStretchMode; padding:Integer; hal:TCellHalign; val:TCellValign):TPicture;
When used with static image from file the code works well problem only with TStram & TPicture while working with DataSet. DataSet is extracting image in junk characters format as it is BLOB type.
This works well
Code: Select all
try
Picture.LoadFromFile('C:\dattaguru.png');
sg.AddPicture(i,j,Picture,True,ShrinkWithAspectRatio,0,haLeft,vaTop);
finally
Stream1.Free;
Code: Select all
try
Field := TBlobField(results.FieldByName(names[i]).AsString);
Stream := results.CreateBlobStream(Field, bmReadWrite);
Picture.Graphic.LoadFromStream(Stream1);
sg.AddPicture(i,j,Picture,True,ShrinkWithAspectRatio,0,haLeft,vaTop);
finally
Stream1.Free;