I was able to store images in my bank, the problem now is just to try to make the images only enter the bank up to a certain size, assuming: 800kb. How to proceed?
Follow the code:
Botão Gravar:
procedure TfrmFoto.SpeedButton1Click(Sender: TObject);
var
Jpeg : TJpegImage;
begin
if OPPicture.execute then
Image1.Picture.LoadFromFile(OPPicture.FileName);
if OPPicture.FileName <> '' then
begin
Jpeg := TJpegImage.Create;
Jpeg.LoadFromFile(OPPicture.FileName);
dmconn.zqFoto.Close;
dmconn.zqFoto.SQL.Clear;
dmconn.zqFoto.SQL.Add('INSERT INTO fotos(nome, fotoAnt) VALUES (:pnome, :pfotoant)');
dmconn.zqFoto.ParamByName('pnome').AsString := edtNome.Text;
dmconn.zqFoto.ParamByName('pfotoant').Assign(Jpeg);
dmconn.zqFoto.ExecSQL;
Jpeg.Free;
end;
end;
And here's the other button:
Botão Ler:
procedure TfrmFoto.SpeedButton2Click(Sender: TObject);
var
sqltexto : string;
Jpeg : TJpegImage;
Stream : TStream;
begin
dmconn.zqFoto.Close;
dmconn.zqFoto.SQL.Clear;
dmconn.zqFoto.SQL.Add('SELECT nome, fotoAnt FROM fotos WHERE nome = :pnome');
dmconn.zqFoto.ParamByName('pnome').AsString := edtNomeLer.Text;
dmconn.zqFoto.Open;
Stream := dmconn.zqFoto.CreateBlobStream(dmconn.zqFoto.Fields[1],BMREAD);
try
Jpeg := TJpegImage.Create;
Jpeg.LoadFromStream(Stream);
Image2.Picture.Assign(Jpeg);
except
// Jpg.Free;
end;