I am trying to load a picture from a specific place in my database to an Image, but my code is running into some problems I can't solve.
Basically I want to load an image that is specified by a unique id, in an application that's meant for different users with different accounts. The image should basically load the picture the user has previously saved.
So first I use the following query to determine the picture I need:
procedure TForm12.BitBtn1Click(Sender: TObject);
begin
  with ADOQuery7 do
  begin
    Close;
    Sql.Clear;
    Sql.Add('SELECT Profile_Picture FROM profile WHERE username='+QuotedStr(edit12.text));
    Open;
  end;
end;
Which works fine, and indeed targets the field that has the picture with the specified username. Then I use the following to load the picture into the empty TImage:
procedure TForm12.BitBtn2Click(Sender: TObject);
var
  AStream: TMemoryStream;
begin
  AStream := TMemoryStream.Create;
  try
    if ADOquery7.Active then
    begin
      TBlobField(ADOQuery7.FieldByName('Profile_Picture')).SaveToStream(AStream);
      AStream.Position := 0;
      Image6.Picture.Graphic.LoadFromStream(AStream);
    end;
  finally
    AStream.Free;
  end;
end;
But I always get an access violation error. Anyone has any ideas what the problem is? The file I load the image from is stored in an OLE Object-column.
 
     
    