[Lazarus] TDBImage -AV [SOLVED] for Jpeg images
Joost van der Sluis
joost at cnoc.nl
Thu Sep 4 22:39:23 CEST 2008
Your solution only works if you know for sure that the field contains a
jpeg-image. The lazarus-code assumes that the blob-fields start with the
extension from the image, so that it can 'detect' what kind of image it
is.
That means offcourse, that you also have to use a TDBEdit to place the
image into the database. Or else the leading extension won't be there.
But I think I saw something else which is strange.
btw: maybe you could send a patch (diff -u) next time, that's easier to
read for people who are used to it. This is kind of a puzzle, althoug
maneagable.
Op woensdag 03-09-2008 om 14:56 uur [tijdzone -0300], schreef Osvaldo
Filho:
> The problem, perhaps, is in s.readstring.
> =================================
> //dbimage.inc line 135
>
> procedure TDBImage.LoadPicture;
> var //s : TMemory; // ( lazarus team)
> s : TMemoryStream; // ( mine )
> GraphExt : string;
> gc : TGraphicClass;
> AGraphic : TGraphic;
>
> begin
> if not FPictureLoaded then
> begin
> FUpdatingRecord := True;
> if not assigned(FDatalink.Field) then
> Picture.Assign(FDatalink.Field)
> else
> if FDatalink.field.IsBlob then
> begin
> if FDatalink.field is TBlobField then
> begin
> if FDatalink.Field.IsNull then
> begin
> Picture.Clear;
> exit;
> end;
> //FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmRead); //
> (lazarus team)
I guess this should be S:=FDatalink.Dataset.CreateBlobstream.....etc
Maybe you also have to add the s.position := 0?
> s := TMemoryStream.create; // ( mine )
> (FDataLink.Field as TBlobField).SaveToStream(s); // ( mine )
> s.Position:= 0; // ( mine )
>
> if (S=Nil) or (s.Size = 0) then
> begin
> Picture.Clear;
> exit;
> end;
> try
> //GraphExt := s.ReadAnsiString; // (lazarus team)
Add 'gc := nil; AGraphic := nil;' here, as mentioned by someone else.
> // gc := GetGraphicClassForFileExtension(GraphExt); //
> (lazarus team)
> // if assigned(gc) then // (lazarus team)
> // begin // (lazarus team)
>
> Picture.Jpeg.LoadFromStream(s); // ( mine )
>
> //AGraphic. := gc.Create; // (lazarus team)
> //AGraphic.LoadFromStream(s); // (lazarus team)
> //Picture.Assign(AGraphic);
> //end;
> finally
> //if assigned(AGraphic) then AGraphic.Free; // (lazarus
> team)
> s.Free;
> end {try}
>
> end
> else
> Picture.Assign(FDataLink.FField);
> end;
> FUpdatingRecord := False;
> end;
> end;
> =================================
>
> 2008/9/2 Osvaldo TCF - Listas <arquivostcf at gmail.com>
> With my image: a .jpg file
> ---------------------------
> in dbimage.inc, line 163:
> try
> GraphExt := s.ReadAnsiString;
>
> gc := GetGraphicClassForFileExtension(GraphExt);
> if assigned(gc) then
> begin
> AGraphic := gc.Create;
> AGraphic.LoadFromStream(s);
>
> Picture.Assign(AGraphic);
> end;
> -------------------------------------------
>
> gc is not assigned, is it correct?
> ==========================================================
>
> The AV ocour here:
> dbimage.inc line 175
> ----------------------
> Picture.Assign(AGraphic);
> end;
> finally
> line 175>> if assigned(AGraphic) then AGraphic.Free;
> s.Free;
> end {try}
> ----------------------
>
> Em Ter, 2008-09-02 às 10:34 +0200, Joost van der Sluis
> escreveu:
>
>
> > Op maandag 01-09-2008 om 12:05 uur [tijdzone -0300], schreef
> Osvaldo
> > Filho:
> > > I can not use tdbimage, access violation!
> > >
> > > loadpicture error?
> >
> > Hmm... I had that working with a few hacks. Maybe that it
> doesn't work
> > anymore with the latest image changes in Lazarus-svn. So
> which fpc and
> > lazarus version are you using?
> >
> > Joost
> >
> >
> > _______________________________________________
> > Lazarus mailing list
> > Lazarus at lazarus.freepascal.org
> > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
>
>
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
--
More information about the Lazarus
mailing list