Pascal to Javascript Compiler
For creating the single-page JavaScript application, the Pascal code of your project is compiled to JavaScript and this JavaScript application runs in the browser. Typically a connection to the server will be made by HTTP REST
requests or via WebSocket
communication. To compile the Pascal code to JavaScript code, the pas2js
compiler is used that is an open-source project and builds on years of experience of the FPC
compiler team. More information about the pas2js
project can be found here: http://wiki.freepascal.org/pas2js
At this moment, this support for the Pascal language is highly compatible with the Delphi language. Some newer Delphi language features are not yet supported in v1.0
though but are on the roadmap. The language features not yet supported but planned for the 2018 – 2019 timeframe are:
- Generics
- Attributes
- Advanced Records
- Advanced RTTI
- Type helpers
- Anonymous functions
For more details about the capabilities of the pas2js compiler, please refer to http://wiki.freepascal.org/pas2js#Compiler
TMS WEB Core ships with a validated version of the pas2js compiler. We recommend using the pas2js
compiler included in the TMS WEB Core distribution as this is the version we test & approve our entire framework and IDE integration with.
RTL
Equally important to move existing VCL or FMX code bases to the web is the support for RTL. A huge part of the Delphi RTL is available and delivered with the compiler. This includes now:
There is a basic Object Pascal RTL, several units from the FPC
Packages are also available
- system
- sysutils
- math
- strutils
- rtlconst
- classes
- contnrs
- typinfo
- objpas
- dateutils
- DB
- js (javascript system objects)
- web (browser provided objects)
- libjquery
For more information about RTL support, please see: http://wiki.freepascal.org/pas2js#RTL
Preprocessor
As a webbrowser does not know the concept of DFM
files to load form configuration from and
as the form designer in the Delphi IDE is technically a VCL form, there is before compiling the
code to JavaScript a preprocessing step. This preprocessing step handles the conversion from
DFM
file to code for initialization of the form. The pre-processor will also convert the unit
namespaces from VCL to WEBLib.
This unit namespace conversion not only applies to unit
names but also when unit name prefixes are explicitly used for types. If there is a special reason
to disallow the pre-processor to skip lines in the code, prefix these lines with the {NOPP}
specifier.
So, the line
will be converted to The line will remain as-is before it is being compiled, i.e.