[Lazarus] Dear developers... TStream.ReadAnsiString
Osvaldo Filho
arquivostcf at gmail.com
Sat Sep 6 23:56:40 CEST 2008
Thanks for all. Sorry my insistence.
Please see this code, it is original, it is in
http://fpc64.firmos.at:8060/browse/Lazarus/trunk/lcl/include/dbimage.inc?r1=9243&r2=10681
See, here, line 161:
161+ GraphExt := s.ReadAnsiString;
My picture is a jpeg image saved on a firebird database.
GraphExt do not receive the extension as expected.
So, this code never executed becose gc is never assigned in
"gc := GetGraphicClassForFileExtension(GraphExt);":
if assigned(gc) then begin AGraphic :=
gc.Create; AGraphic.LoadFromStream(s);
Picture.Assign(AGraphic); end;
==================================
88132 procedure TDBImage.LoadPicture; [image:
<]<http://fpc64.firmos.at:8060/browse/Lazarus/trunk/lcl/include/dbimage.inc?r1=9243&r2=10681#seg7>[image:
>]<http://fpc64.firmos.at:8060/browse/Lazarus/trunk/lcl/include/dbimage.inc?r1=9243&r2=10681#seg9>
133+
134+var s : Tstream; 135+ GraphExt : string; 136+
gc : TGraphicClass; 137+ AGraphic : TGraphic; 138+
89139 begin [image:
<]<http://fpc64.firmos.at:8060/browse/Lazarus/trunk/lcl/include/dbimage.inc?r1=9243&r2=10681#seg8>[image:
>]<http://fpc64.firmos.at:8060/browse/Lazarus/trunk/lcl/include/dbimage.inc?r1=9243&r2=10681#seg10>
90 - if not FPictureLoaded 91 - and (not Assigned(FDataLink.Field) or
FDataLink.Field.IsBlob) then 92 - Picture.Assign(FDataLink.Field); 140
+ if not FPictureLoaded then 141+ begin 142+ FUpdatingRecord :=
True; 143+ if not assigned(FDatalink.Field) then
Picture.Assign(FDatalink.Field) 144+ else 145+ if
FDatalink.field.IsBlob then 146+ begin 147+ if FDatalink.field
is TBlobField then 148+ begin 149+ if
FDatalink.Field.IsNull then 150+ begin 151+
Picture.Clear; 152+ exit; 153+ end; 154+ s :=
FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmRead); 155+ if
s.Size = 0 then 156+ begin 157+ Picture.Clear;
158+
exit; 159+ end; 160+ try 161+ GraphExt :=
s.ReadAnsiString; 162+
163+ gc := GetGraphicClassForFileExtension(GraphExt);
164+
if assigned(gc) then 165+ begin 166+ AGraphic :=
gc.Create; 167+ AGraphic.LoadFromStream(s); 168+
169+ Picture.Assign(AGraphic); 170+ end;
171+
finally 172+ if assigned(AGraphic) then AGraphic.Free;
173+
s.Free; 174+ end {try} 175+
176+ end 177+ else 178+
Picture.Assign(FDataLink.FField); 179+ 180+ end; 181+
FUpdatingRecord := False; 182+ end;
93183 end; 94184
==================================
2008/9/6 Felipe Monteiro de Carvalho <felipemonteiro.carvalho at gmail.com>
> If you want to convert raw data to a string you should assign the
> stream holding the data to a TStringStream.
>
> ReadAnsiString can only read data written with WriteAnsiString (or if
> you took care to imitate it's format).
>
> --
> Felipe Monteiro de Carvalho
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20080906/8b5c357e/attachment-0007.html>
More information about the Lazarus
mailing list