Den 2017-12-22 kl. 12:00, skrev Michael Van Canneyt:
On Wed, 20 Dec 2017, Reimar Grabowski wrote:

On Wed, 20 Dec 2017 15:14:50 +0100
Ingemar Ragnemalm<inge...@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;

Yes, something like that. I have found JS examples that does this but can't see how to make pas2js do it.

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.

One reason is to collect information in one place. Making HTML load it gives me two steps to the file instead of one. More chances to do it wrong.

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).

Ah. They just remained from an example I worked from.

Text flicker is most likely caused by not double buffering. I need to generate an image off-screen. Nothing strange with that, just one more thing to figure out in the JS environment.

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.

There is no interactivity, and no client-server communication, but this is my *first*, my 
"proof of concept" for the platform, like Hello World but with some more features 
(animation, random numbers, graphics elements). Doing *something* with it myself, showing myself 
the potential, making a kind of "thanks" for it and a Christmas greeting atthe same time. 
Interactivity is the next step, and the ability to save data somewhere.

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"...

Exactly. I get a cross-platform solution with no installations, in a way that users are increasingly used to. And I can write it in FPC, which I am a lot more happy with than a rubbish language like JavaScript! For me it opens a lot of possibilities!

But let me get back to my current problems. I can accept loading images through HTML for now, but how can I load and play sounds? There is an "Audio" API in JavaScript but it seems that pas2js doesn't support it, it can't find play(). I have searched web.pas and a few others for it. Where do I start to fix that?

/Ingemar

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to