I have figured out how to store and retrieve a JPEG file in my database. If the JPEG file is there, I can easily edit it, but if I try to enter a new record, I always get JPEG Error #42. Here are my code snippets. I use btnLabelGetClick to upload an image to the stream to be posted.
procedure TfrmWines.AutoSetDataChange(Sender: TObject; Field: TField);
var
JPG: TJPEGImage;
ms: TMemoryStream;
begin
JPG := TJPEGImage.Create;
ms := TMemoryStream.Create;
try
TBlobField(wdatamod.mywines.FieldByName('winelabel')).SaveToStream(ms);
ms.Position := 0;
JPG.LoadFromStream(ms);
Image1.Picture.Assign(JPG);
finally
JPG.Free;
ms.Free;
end;
end;
procedure TfrmWines.btnAddClick(Sender: TObject);
begin
ButtonsEnter;
//btnLabelGet.Click;
wdatamod.mywines.Insert;
edWinename.SetFocus;
end;
procedure TfrmWines.btnLabelGetClick(Sender: TObject);
begin
if OpenPictureDialog1.Execute(Self.Handle) then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
I solved this AND coded the way to add a standing image for all new records if I don't have an image I want to use:
Here is the new code that prevents the JPEG Error #42 on adding a new record