[Pas2js] Error Picture.Data Access Violation

Michael Van Canneyt michael at freepascal.org
Sat Aug 18 16:43:58 CEST 2018



On Sat, 18 Aug 2018, warleyalex via Pas2js wrote:

> TWebImageControl can display an image on the Lazarus form. TWebImageControl
> is similar to a LCL TImage.
>
> TImage is written using DefineProperties, i.e. it needs TReader and a binary
> stream to read. The pas2js classes units don't have a TStream mechanism to
> read files like Lazarus. The serialization LFM to PAS we have an output like
> this:
>
>  with WebImageControl1 do begin
>    Name:='WebImageControl1';
>    Parent:=Self;
>    Left:=160;
>    Height:=16;
>    Top:=104;
>    Width:=16;
>    ExecCustomCSP(Picture,[ { data of the Picture.png here is packed } ]);
>  end;
>
> So, this needs a replacement. Instead of "ExecCustomCSP" the serialization
> should emit something like:
> Picture.LoadFromFile('Picture.png');
>>
> The issue is no record is kept of where the image originated. You'd need to
> track them. You'd typically use a variable at the same scope at the image
> control to store the filename. So, the TWebImageControl have the URL
> property, I can use this property to store the path/filename of the image
> like this:
> ------------------------------------------------------------------
> But at design time, I can not re-open the project,  have to remove the
> Picture.Data so, it can not display an image on the form.
>
> Any idea?

Your whole mechanism seems farfetched to me.

Why don't you use the data url ?
https://stackoverflow.com/questions/16449445/how-can-i-set-image-source-with-base64

That way you can just write the data to the lfm as a base64 string.

You should IMHO provide the user with 2 mechanisms:
1. an URL
2. The above data mechanism.
And not force the user to use 1 mechanism.

The user can pick whatever he thinks is best. The code can then load the image at
run and design time, depending on the property that was used..

Michael.


More information about the Pas2js mailing list