[fpc-pascal] First pas2js public release
Reimar Grabowski
reimgrab at web.de
Wed Dec 20 17:30:54 CET 2017
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.
> Well, I could do it in Java before but that isn't as universal as
> JavaScript.
For this concrete project you could have done it with pure JS which would be about 950 lines less of JS code. ;)
Nonetheless, nice work.
R.
More information about the fpc-pascal
mailing list