Board index » delphi » Saving and loading JPEG from Paradox7 table- Error on load

Saving and loading JPEG from Paradox7 table- Error on load

Quote
Jason McKnight wrote:
> I think I have successfully stored a  JPG in a Paradox 7 BLOB field, but I
> can't get the retrieval to work. I am using Delphi4 under NT4 SP3.

> Here is my code for saving a JPG to the BLOB field:

> Try
>         begin
>             tblPic.Edit;
>             TBlobField(tblPic.FieldByName('Pic')).BlobType := ftTypedBinary
> ;

> TBlobField(tblPic.FieldByName('Pic')).LoadFromFile(flbDriveA.Items.Strings[f
> lbDriveA.ItemIndex]);
>         end;
>  Finally
>               tblPic.Post;

>  End;

> My Table is named tblPic and has a valid BLOB field called PIC, flbDriveA is
> a FileListBox pointed at DriveA. I am not sure if setting the field type to
> fTypedBinary is necessary, but it seems to save that way. (I have gone
> through many iterations of this code)
> I Type my field as a TBlobField because it doesnt seem to work if I just try
> to assume that the Field is a BLOB.
> Then I update my DB.

> The database MB file gets larger as I add JPG's but I can't seem to retrieve
> them. Here is my retrieve code:

> Since TDBImage does not support JPG's directly (I don't think it does
> anyway) I am just trying to load the information to a stream and Assign it
> to a TJPGImage. This code came directly from DevelopersHref.com in an
> article by Steve Koterski of Borland but it does not seem to work for me.

> procedure TForm1.tblPicAfterScroll (Dataset:Tdataset);
> var
>     MS: TmemoryStream;
>     J1: TJPEGImage;
> begin
>     J1:= TJPEGImage.create;
>     MS:= TMemoryStream.create;
> try
>     TBlobField(DataSet.FieldByName('Pic')).SaveToStream(MS);
>     MS.Seek(soFromBeginning,0);

>     with J1 do begin
>     PixelFormat:=jf24Bit;
>     Scale := jsFullSize;
>     Grayscale:=False;
>     Performance:=jpBestQuality;
>     ProgressiveDisplay := True;
>     ProgressiveEncoding :=TRUE;
>     LoadFromStream(MS);
>     end;
>     Image1.Picture.Graphic.Assign(J1);
> finally
>     J1.Free;
>     MS.Free;
> end;

> end;

> The above code compiles just fine, but it Barfs on
> Image1.Picture.Graphic.Assign(J1) and gives an access violation at 0048803b.

> Thanks in advance for any help.

> Jason McKnight

  The Image1 component might not be able to assign the J1 variable as it is not
a bitmap try copy rect to a bitmap canvas from the J1 canvas then try assigning
the bitmap.
 

Re:Saving and loading JPEG from Paradox7 table- Error on load


I think I have successfully stored a  JPG in a Paradox 7 BLOB field, but I
can't get the retrieval to work. I am using Delphi4 under NT4 SP3.

Here is my code for saving a JPG to the BLOB field:

Try
        begin
            tblPic.Edit;
            TBlobField(tblPic.FieldByName('Pic')).BlobType := ftTypedBinary
;

TBlobField(tblPic.FieldByName('Pic')).LoadFromFile(flbDriveA.Items.Strings[f
lbDriveA.ItemIndex]);
        end;
 Finally
              tblPic.Post;

 End;

My Table is named tblPic and has a valid BLOB field called PIC, flbDriveA is
a FileListBox pointed at DriveA. I am not sure if setting the field type to
fTypedBinary is necessary, but it seems to save that way. (I have gone
through many iterations of this code)
I Type my field as a TBlobField because it doesnt seem to work if I just try
to assume that the Field is a BLOB.
Then I update my DB.

The database MB file gets larger as I add JPG's but I can't seem to retrieve
them. Here is my retrieve code:

Since TDBImage does not support JPG's directly (I don't think it does
anyway) I am just trying to load the information to a stream and Assign it
to a TJPGImage. This code came directly from DevelopersHref.com in an
article by Steve Koterski of Borland but it does not seem to work for me.

procedure TForm1.tblPicAfterScroll (Dataset:Tdataset);
var
    MS: TmemoryStream;
    J1: TJPEGImage;
begin
    J1:= TJPEGImage.create;
    MS:= TMemoryStream.create;
try
    TBlobField(DataSet.FieldByName('Pic')).SaveToStream(MS);
    MS.Seek(soFromBeginning,0);

    with J1 do begin
    PixelFormat:=jf24Bit;
    Scale := jsFullSize;
    Grayscale:=False;
    Performance:=jpBestQuality;
    ProgressiveDisplay := True;
    ProgressiveEncoding :=TRUE;
    LoadFromStream(MS);
    end;
    Image1.Picture.Graphic.Assign(J1);
finally
    J1.Free;
    MS.Free;
end;

end;

The above code compiles just fine, but it Barfs on
Image1.Picture.Graphic.Assign(J1) and gives an access violation at 0048803b.

Thanks in advance for any help.

Jason McKnight

Re:Saving and loading JPEG from Paradox7 table- Error on load


Hi there,

you might want to try a Image1.Picture.Assign(J1);

maybe that will work.

--
Martijn Tonies
http://surf.to/seal97
(Check the Delphi components page)

<none of the text written above has got anything to do with Euro Partners
Informatici BV>

System Development
Euro Partners Informatici BV
http://www.euro-partners.nl

Jason McKnight heeft geschreven in bericht
<4ayL1.429$lk2.768...@news3.ispnews.com>...

Quote
>I think I have successfully stored a  JPG in a Paradox 7 BLOB field, but I
>can't get the retrieval to work. I am using Delphi4 under NT4 SP3.

>Here is my code for saving a JPG to the BLOB field:

>Try
>        begin
>            tblPic.Edit;
>            TBlobField(tblPic.FieldByName('Pic')).BlobType := ftTypedBinary
>;

>TBlobField(tblPic.FieldByName('Pic')).LoadFromFile(flbDriveA.Items.Strings[
f
>lbDriveA.ItemIndex]);
>        end;
> Finally
>              tblPic.Post;

> End;

>My Table is named tblPic and has a valid BLOB field called PIC, flbDriveA
is
>a FileListBox pointed at DriveA. I am not sure if setting the field type to
>fTypedBinary is necessary, but it seems to save that way. (I have gone
>through many iterations of this code)
>I Type my field as a TBlobField because it doesnt seem to work if I just
try
>to assume that the Field is a BLOB.
>Then I update my DB.

>The database MB file gets larger as I add JPG's but I can't seem to
retrieve
>them. Here is my retrieve code:

>Since TDBImage does not support JPG's directly (I don't think it does
>anyway) I am just trying to load the information to a stream and Assign it
>to a TJPGImage. This code came directly from DevelopersHref.com in an
>article by Steve Koterski of Borland but it does not seem to work for me.

>procedure TForm1.tblPicAfterScroll (Dataset:Tdataset);
>var
>    MS: TmemoryStream;
>    J1: TJPEGImage;
>begin
>    J1:= TJPEGImage.create;
>    MS:= TMemoryStream.create;
>try
>    TBlobField(DataSet.FieldByName('Pic')).SaveToStream(MS);
>    MS.Seek(soFromBeginning,0);

>    with J1 do begin
>    PixelFormat:=jf24Bit;
>    Scale := jsFullSize;
>    Grayscale:=False;
>    Performance:=jpBestQuality;
>    ProgressiveDisplay := True;
>    ProgressiveEncoding :=TRUE;
>    LoadFromStream(MS);
>    end;
>    Image1.Picture.Graphic.Assign(J1);
>finally
>    J1.Free;
>    MS.Free;
>end;

>end;

>The above code compiles just fine, but it Barfs on
>Image1.Picture.Graphic.Assign(J1) and gives an access violation at
0048803b.

>Thanks in advance for any help.

>Jason McKnight

Other Threads