![]() |
#1
|
|||
|
|||
![]()
procedure TfrmWines.FormActivate(Sender: TObject);
var Field: TBlobField; Stream: TStream; Jpg: TJPEGImage; begin if wdatamod.mywines.Active then begin Field := TBlobField(wdatamod.mywines.FieldByName('winelabel ')); Stream := wdatamod.mywines.CreateBlobStream(Field, bmRead); Jpg := TJPEGImage.Create; try Jpg.LoadFromStream(Stream); DBImage1.Picture.Graphic := Jpg; finally Jpg.Free; Stream.Free; end; end; end;
__________________
Using Delphi 2010 Professional as a Novice Programmer - self taught |
#2
|
|||
|
|||
![]()
There are quite a few discussions about this error on Google. Check it out. They say it is because the file does not get loaded properly.
George |
#3
|
|||
|
|||
![]()
Yes, I have tried and looked at all these examples, ad naseum, and still can't get this to fly. There has got to be a way in Delphi 2010 to get this to work without exceptions.
__________________
Using Delphi 2010 Professional as a Novice Programmer - self taught |
#4
|
|||
|
|||
![]()
I have figured out how to at least store and retrieve the jpeg files in the database. But if the blobfield is empty, I always get jpeg #42 error until I load an image in the field. I can edit the database just fine, but when I try to add a new record I'm back to JPEG Error #42 again. I can go ahead and enter a record by bypassing the pop, but it's annoying. Here's my code to show images and insert a new record
Code:
procedure TfrmWines.AutoSetDataChange(Sender: TObject; Field: TField); var JPG:TJPEGImage; ms:TMemoryStream; begin 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; 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; procedure TfrmWines.btnSaveClick(Sender: TObject); var AStream : TMemoryStream; begin AStream := TMemoryStream.Create; try Image1.Picture.Graphic.SaveToStream(AStream); AStream.Position := 0; if wdatamod.mywines.Active then begin TBlobField(wdatamod.mywines.FieldByName('winelabel')).LoadFromStream(AStream); end; finally AStream.Free; end; wdatamod.mywines.Post; ButtonsNormal; end; Can someone offer some insight. How can I get past an empty blobfield on inserting new record? How can I allow it to not save an image if don't want to.? Thanks in advance.
__________________
Using Delphi 2010 Professional as a Novice Programmer - self taught |
#5
|
|||
|
|||
![]()
I solved this and found the way to add a standard image to the database when I don't have and image. I only show the code snippet that fixed what I wanted below
Code:
procedure TfrmWines.AutoSetDataChange(Sender: TObject; Field: TField); var JPG:TJPEGImage; ms:TMemoryStream; begin if autoset.DataSet.State = dsInsert then begin image1.Picture.Graphic.LoadFromFile('q:\sourcecode\mycellar\images\blk_wht_glass.jpg'); Exit; end; 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; end;
__________________
Using Delphi 2010 Professional as a Novice Programmer - self taught |
![]() |
Thread Tools | |
Display Modes | |
|
|