Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-09

TDBImage -AV [SOLVED] for Jpeg images

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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)
    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)
          // 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

Show quoted text 50 lines
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 > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080903/894a8e32/attachment.html

Reply by email

Burkhard Carstens
to Osvaldo Filho

Am Mittwoch, 3. September 2008 19:56 schrieb Osvaldo Filho: [..]

Show quoted text 10 lines
> 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} > ----------------------

I didn't read the whole thread but one thing comes to mind: AGraphics is a local var, so it is not initialized (IIRC). Therefore assigned(AGraphics) (which just checks for non-nil pointer) returns probably true, even if it does not point to TGraphic instance. Just adding "AGraphics:=nil" at the beginning of the procedure might resolve the issue.

regards
Burkhard

Reply by email

Osvaldo Filho
to Burkhard Carstens
> line 175>> if assigned(AGraphic) then AGraphic.Free;
This is not the problem, the problem is the fact that this code never
executed:
         if assigned(gc) then
           begin
           AGraphic := gc.Create;
           AGraphic.LoadFromStream(s);
           Picture.Assign(AGraphic);
           end;

Perhaps the problem is in :
FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmRead); // (lazarus team)
or
s.readansistring; (please, see original code)
2008/9/4 Burkhard Carstens

Show quoted text 28 lines
Am Mittwoch, 3. September 2008 19:56 schrieb Osvaldo Filho: [..] > > 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} > > ---------------------- I didn't read the whole thread but one thing comes to mind: AGraphics is a local var, so it is not initialized (IIRC). Therefore assigned(AGraphics) (which just checks for non-nil pointer) returns probably true, even if it does not point to TGraphic instance. Just adding "AGraphics:=nil" at the beginning of the procedure might resolve the issue. regards Burkhard _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080904/728317ce/attachment.html

Reply by email

Burkhard Carstens
to Osvaldo Filho
Osvaldo Filho wrote 39 lines
> > line 175>> if assigned(AGraphic) then AGraphic.Free; This is not the problem, the problem is the fact that this code never executed: if assigned(gc) then begin AGraphic := gc.Create; AGraphic.LoadFromStream(s); Picture.Assign(AGraphic); end; Perhaps the problem is in : FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmRead); // (lazarus team) or s.readansistring; (please, see original code) 2008/9/4 Burkhard Carstens > Am Mittwoch, 3. September 2008 19:56 schrieb Osvaldo Filho: > [..] > > > > 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} > > > ---------------------- > > I didn't read the whole thread but one thing comes to mind: > AGraphics is a local var, so it is not initialized (IIRC). > Therefore > assigned(AGraphics) (which just checks for non-nil pointer) returns > probably true, even if it does not point to TGraphic instance. Just > adding "AGraphics:=nil" at the beginning of the procedure might > resolve the issue.

Sorry, I was just talking about the AV, which should not appear, even if GetGraphicClassForFileExtension(GraphExt) returns nil.

regards
Burkhard

Reply by email

Joost van der Sluis
to Osvaldo Filho: The problem, perhaps, is in s.readstring. ================================= //dbimage.inc…

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:

Show quoted text 29 lines
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?
Show quoted text 11 lines
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.
Show quoted text 89 lines
// 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 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 > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Osvaldo Filho
to Joost van der Sluis

Thankyou Joost, i will change and test.

2008/9/4 Joost van der Sluis

Show quoted text 158 lines
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 > 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 > > > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > > > > > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus -- _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080905/87eabacc/attachment.html

Reply by email