I have problem to display my Picture in TImage from my MySql database using Delphi.
I save picture to my database with this code and work Perfectly.
var
AStream : TMemoryStream;
AStream := TMemoryStream.Create;
try
Image1.Picture.Graphic.SaveToStream(AStream);
AStream.Position := 0;
if ADODataSet1.Active then
begin
ADODataSet1.Edit;
TBlobField(ADODataSet1.FieldByName('MyField')).LoadFromStream(AStream);
ADODataSet1.Post;
end;
finally
AStream.Free;
end;
But, problem is when I want to retrieve that Pictures. I use this code but I can display only first image from my database. I uses this code on DBGrid event - OnDrawColumnCell. AND WHEN I USE THIS CODE I'M GETTING MESSAGE JPEG ERROR #42!
var
AStream : TMemoryStream;
begin
AStream := TMemoryStream.Create;
try
if ADODataSet1.Active then
begin
TBlobField(ADODataSet1.FieldByName('MyField')).SaveToStream(AStream);
AStream.Position := 0;
Image1.Picture.Graphic.LoadFromStream(AStream);
end;
finally
AStream.Free;
end;
end;
Can somebody show me how to Fix This Problem. Thank you.