[Lazarus] Strange issue with TImage and lazarus 2.2.2

Werner Pamler werner.pamler at freenet.de
Thu Jun 30 18:20:56 CEST 2022


Am 30.06.2022 um 17:03 schrieb Ondrej Pokorny via lazarus:
> On 30.06.2022 16:54, Werner Pamler via lazarus wrote:
>> Am 30.06.2022 um 15:11 schrieb Mattias Gaertner via lazarus:
>>> Maybe instead of the GraphicClass.ClassName the first extension can be
>>> written.
>>> That means, that an old IDE cannot read the graphic.
>> This will break Delphi compatibility, i.e. forms with an image in 
>> which the Picture has been loaded by Delphi will not be readable by 
>> Lazarus any more, and vice versa. Just checked again the signature 
>> that Delphi writes to the begin of the Picture.Data: it's the class 
>> name, not the extension.
>
> And what about writing the extension to the data end?
>
>     Picture.Data = {
>       0B 54 49 6D 61 67 69 6E 67 50 4E 47 89 50 4E 47 0D 0A 1A 0A 00 
> 00 00 0D 49 48 44 52 00 00 01 C6
>       11 T  I  m  a  g  i  n  g  P  N  G                // 11 is the 
> length byte
>       03 p  n  g
>
> That should be both Delphi and legacy Lazarus compatible if the reader 
> reads only the defined count of bytes for the classname?
>
But isn't this the same problem? When Vampyre is not installed, and the 
streamer sees the TImageingPNG classname there is no way how to find the 
end of the Picture.Data block.


> Newer Lazarus versions would first search the extension and if not 
> found they search for the classname.
>
Where's that? AFAICS, TPicture only looks for the classname. From Laz/main:

procedure TPicture.ReadData(Stream: TStream);
var
   GraphicClassName: Shortstring;
   NewGraphic: TGraphic;
   GraphicClass: TGraphicClass;
   ok: boolean;
begin
*  Stream.Read(GraphicClassName[0], 1);**
**  Stream.Read(GraphicClassName[1], length(GraphicClassName));*
   GraphicClass := GetPicFileFormats.FindClassName(GraphicClassName);
   NewGraphic := nil;
   if GraphicClass <> nil then begin
     NewGraphic := GraphicClass.Create;
     ok:=false;
     try
       NewGraphic.ReadData(Stream);
       ok:=true;
     finally
       if not ok then NewGraphic.Free;
     end;
   end;
   FGraphic.Free;
   FGraphic := NewGraphic;
   if NewGraphic <> nil then begin
     NewGraphic.OnChange := @Changed;
     NewGraphic.OnProgress := @Progress;
   end;
   Changed(Self);
end;

procedure TPicture.WriteData(Stream: TStream);
var
   GraphicClassName: ShortString;
begin
   with Stream do
   begin
     if Graphic <> nil then
       GraphicClassName := Graphic.ClassName
     else
       GraphicClassName := '';
*    Write(GraphicClassName, Length(GraphicClassName) + 1);*
     if Graphic <> nil then
       Graphic.WriteData(Stream);
   end;
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20220630/7fd78273/attachment-0001.htm>


More information about the lazarus mailing list