Jump to content

Webworkers (SMS 2.2.2)

Recommended Posts


looking at the WebWorkers demo (..\Smart Mobile Projects\Demos\Featured Demos\API\WebWorker), it seems to only work because the "worker.js"

("..\API\WebWorker\www\") file was compiled with a different compiler version.


If I actually recompile the worker project with the 2.2.2 compiler the demo then fails and reports the following error : "Uncaught ReferenceError: window is not defined [line #193]".


Project options are set to deploy the compiled file in the "output" folder and not the "www" where all the files are located, as such it is the outdated worker.js file that is served to the browser instead of the freshly compiled.


Steps to reproduce :


1. Open Worker.sproj (..\Smart Mobile Projects\Demos\Featured Demos\API\WebWorker)

2. Compile project

3. Move "worker.js" from \output folder to \www folder

4. run index.html or execute the main project through IDE

Link to post
Share on other sites
  • 4 weeks later...
  • Administrators

Hey Nortg,

sorry for the late response!

I am not sure whether you have the latest version installed. But I could not reproduce your error. For me, it worked without problems. Are there maybe any specific compiler settings?

What is your SMS version installed?

Link to post
Share on other sites

Hey Dennis,my SMS version is that available on the website



Smart Mobile Studio 2.2.2

April 18th, 2016



if you follow my steps to reproduce you should run into the same issue, but let me expand,



the webworker demo involves two projects (sproj), "Main Application.sproj" and "Worker.sproj". If you only run the main application then everything will work because inside the /www folder in the same directory, a pre-compiled worker.js already exists. The problem is that this pre-compiled js file was not compiled with the 2.2.2 version. If you actually start the Worker.sproj and compile it, it will drop a fresh worker.js file in the /output folder, and this is the important thing, the project is set to create the file in the output folder and not the www folder of the main project so on it's face you might not see this and think that it works. Simply copy the worker.js file from the output folder to the www folder overwritting the old worker.js file with the new one. Then launch the main application and you will see that it does not work and reports previously mentioned error.


Best Regards

Link to post
Share on other sites

This project SMS_INSTALL_FOLDER\projects\Featured Demos\API\WebWorker\ is buggy with the current SMS Please fix it.


We have to construct/wrapping the main code with exception handling, like this:

uses  workerthread;  

var mTemp: TThread;  
  mTemp := TThread.Create;  
  on e: Exception do ;  
...this is weird, we have to wrap the main code with try..except, then the compiler will emit the expected Exception information in the Worker project.


---> Exception information <---

var Exception={	$ClassName: "Exception",	
$Parent: TObject,	
$Init: function () { FMessage="" },	
Create: function (s,Msg) { s.FMessage=Msg; return s }}
There are another minour issues, in the "Main Application" project it seems like we have an issue with window.postMessage HTML5 method to allow safe communication between window/frames.

TWebWorkerThread.PostMessage <> window.postMessage. An workaround would be renaming the method to work as expected.


Anyway, here is the fixed project: https://www.dropbox.com/s/pd71dlz5cncwfki/WebWorker.rar?dl=0

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...