[fpc-pascal] First pas2js public release

Michael Van Canneyt michael at freepascal.org
Fri Dec 22 08:53:03 CET 2017



On Wed, 20 Dec 2017, Reimar Grabowski wrote:

> On Wed, 20 Dec 2017 15:14:50 +0100
> Ingemar Ragnemalm <ingemar at ragnemalm.se> wrote:
>
>> Although I would like to make some improvements - who doesn't? To be 
>> precise, I want to figure out a way to play sounds, and I want image 
>> loading directly in the code and not dependent on the HTML. Any ideas 
>> about that?
> First of all I know nothing about pas2js, but...
> As your code is running solely in the browser there is no option to load it from file for security reasons.
> But you can embed the binary image data in the code (as Uint8Array) or you can use XHR (pas2js will surely support this somehow) to fetch the image data via HTTP.
> Once you have the data put it into a blob, create an url and finally use that as you image url.
> So you need pascal code that will produce this JS code:
>
> var blob = new Blob([data], { type: "image/png" }); // where data is your Uint8Array
> var url = URL.createObjectURL(blob);
> var image = new Image();
> image.src = url;
>
> But I don't see anything wrong with putting them in the HTML. For more flexibility you could create the HTML via a template engine or something but I would only load them from JS if there is a good reason to do so.
>
> While you are updating your code you can remove the two dependencies on bootstrap (as they are not satisfied anyway and I think the whole fpReport dir is superflous) and perhaps do something about the flickering of the text (although this may be a little bit too much asked).
>
>> It feels really nice to have my first Pascal web application running! 
> Not dissing you or your work or pas2js but I fail to see the web application part. There is no communication between client and server. Actually there is no server side code at all and there is no interactivity. In my book this is a static page, but perhaps I miss something.

That is one of the points of pas2js. To allow you to program the browser.

There is no need for a server. You can make e.g. a chess application that runs
100% in the browser, using a single HTML file. You can embed the JS and
images in the HTML itself, and thus your HTML file is the 'executable'.

See the browser as a desktop. Your program runs in that desktop. 
If need be, this program can contact a server - the classical 
client/server model, using HTTP as the protocol - but this is by no means a necessity.

In that sense, the demo demonstrates this. The server is just there for you
to be able to download the "program"...

Michael.



More information about the fpc-pascal mailing list