SlideShare a Scribd company logo
1 of 22
Download to read offline
22
Pas2JS Integration
Nov. 2023, Max Kleiner
 Combine the world of web development with a
desktop development world.
 IDE / RAD / CLI / Shell / Scripts
 Pas2JS and JS1Pas Scripting maXbox4
 https://wiki.freepascal.org/pas2js
 This session shows you various ways of having
JS in your application.
maXbox4exe
Digital unterschrieben von
maXbox4exe
Datum: 2023.08.11 23:23:51
+02'00'
2 / 22
Agenda
 JS1Pas – JS integrate in Delphi Form
 Hybrid Mode as TWebBrowser.
 Mapping from JS Lib (ex. unit ChartJS; Pascal
mapping for ChartJS: https://www.chartjs.org)
 Pas2Js – from pas source to a *.js
 Today JS/HTML/CSS/Websockets is a main
stack for building frontends and user interfaces.
It has great libraries, frameworks and gigantic
community.
3 / 22
From J1Pas to Hybrid
 No Makefiles: Compiler searches for all
required source files and RTL's and
automatically recompiles all changed files.
 Simple Solution: OpenWeb(JSApp);
 Local or Server:
 Const JSAPP2 = 'C:Program
FilesStreamingIBZ2021Module2_3EKON27text2jstester.html';
 Const JSAPP3 =
'https://raw.githack.com/breitsch2/maXbox4/master/assets/text2jstest
er.html';
4 / 22
Hybrid Mode
 A hybrid application (hybrid app) is one that
combines elements of both native and Web
applications.
 In practice it means that you build native
applications with a web stack, engine or node.
There are several libraries like Electron or
NW.js, but we can also build such applications
using Delphi or Lazarus.
https://raw.githack.com/breitsch2/maXbox4/master/assets/basicpdf2.html
5 / 22
Hybrid Mode
 ScriptGate for ex. is a cool library that allows to
call Delphi methods from JS code in
TWebBrowser. Also the other way round.
 Now I will create a script application and place
webbrowser into a form. Then we add some
lines of code:
WebBrowser1:= TWebBrowser.create(form1);
with WebBrowser1 do begin
TWinControl(WebBrowser1).Name:= 'MyWebBrowser2JS';
// Parent property is read-only unless cast
TWinControl(WebBrowser1).Parent:= form1;
https://raw.githack.com/breitsch2/maXbox4/master/assets/text2jstester.html
6 / 22
Be aware of
 cFeatureBrowserEmulation =
 'MicrosoftInternet
ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION';
 Late binding possible:
 objIE:= CreateOleObject('InternetExplorer.Application');
 Silent mode to debug and events:
Silent := False;
 OnDocumentComplete:= @WebBrowserDocumentComplete;
Demo: 1235_Weatherboxsep2023_EKON27_API_JS_Integrate1.txt
7 / 22
API Keys
 Where you store Developer-Keys.
 Use Read-only keys
 These API keys are specifically designed to be
used in client-side code. They can only read
data from the API, not write to it or change
anything. So even someone got a hold of a
read-only API key, they couldn't do any damage
to your data.
8 / 22
API Key Solution
 My preferred solution is to create a config.json
file and fetch() config data in Javascript file.
 config.json
 {
 "apiKey": "My read-only API key"
 }
 script.js
 fetch('/config.json').then(function (config) {
 console.log('API key:', config.apiKey);
 });
Demo: 1241_pixabay_api_tester.pas
9 / 22
Just a Shell
 IDE for Console or Terminal
10 / 22
Pas2JS
 Pas2js is an open source Pascal to JavaScript transpiler. It
parses Object Pascal or maXbox files and emits JScript. It
takes Delphi/Lazarus projects and modules (.DPR, .LPR,
.PAS, .PP) and converts them to JavaScript (.JS). The JS is
currently of level ECMAScript 5 and should run in any browser
or in Node.js (target “nodejs”). It is available in 5 forms:
 as a library
 as a command-line program
 as a webserver
 as a node.js program
 as a program running in the browser.
11 / 22
Using libpas2js.dll
 You can build libpas2js.dll directly by using Lazarus or lazbuild
to compile
 compiler/utils/pas2js/pas2jslib.lpi
Anyway you should now have the library:
 libpas2js.so on Linux
 libpas2js.dynlib on macOS
 libpas2js.dll on Windows
It simply passes the command line parameters to run the
compiler, so it behaves pretty much like the command line
compiler pas2js.exe.
12 / 22
Let's compile
 It transpiles from actual Pascal source, it has no
intermediate .ppu files. That means all sources must
always be available.
 Const pas2jsPATH = 'C:Program
FilesStreamingmaxbox4examplespas2js-windows-
2.2.0pas2js-windows-2.2.0bini386-win32';
 writeln(GETDOSOutput('cmd.exe /c "'+
 pas2jsPATH+'pas2js" -Jc -Jirtl.js -Tbrowser
....demochartjsdemoradar.lpr', Pas2jsPATH));

 Demo: 1238_create_process_etl_javascript.txt
13 / 22
After Transpile
 Pas2JS Compiler version 2.2.0 [2022/02/22] for Win32 i386
 Copyright (c) 2021 Free Pascal team.
 C:Program FilesStreamingmaxbox4examplespas2js-
windows-2.2.0pas2js-windows-
2.2.0demochartjsdemotime.lpr(9,3) Hint: Unit "Math" not used
in demotime
 Info: 9627 lines in 7 files compiled, 0.1 secs

 mX4 executed: 11/08/2023 15:21:40 Runtime: 0:0:2.272
Memload: 54% use
14 / 22
Sign Compatability
 Simply add the config.json to your .gitignore
and treat it the same as you would a .env file.
 Sign your script (yes we can, for windows)
 TOSIGNFILE:= '1235_tetris_signed.js'
 if fileExists(CERTFILE) then begin
 writeln(botostr(ChDirW(TOOLPATH)));
 passfromfile:= FileToString('./certs/passfile2.txt')
 ExecuteShell('signtool.exe', 'sign /f'
 +' certs/maxbox4exe.pfx /p '+passfromfile
 +' /t http://timestamp.digicert.com '+TOSIGNFILE);
15 / 22
pas2js Electron Web App
 Install Electron and you must install node.js.
 Windows, MacOS:
https://nodejs.org/en/download/
 Debian, Ubuntu:
 Check that node and npm work:
 node -v
 npm -v
 C:boxmynodejsnode_moduleselectrondistelectron.exe
https://wiki.freepascal.org/pas2js_Electron_Web_Application
16 / 22
Class Definitions
Through external class definitions, the trans/compiler can use
JavaScript classes:
 All classes available in the JavaScript runtime, and in the
browser are available
 through import units (comparable to the windows or Unix units
for the native compiler).
 For Node.js, basic support for the nodejs runtime environment
is available.
 An import unit for jQuery is available (libjquery)
 a converter from maXbox to lpr project files
17 / 22
Distribution
 For the generated code to work, a small JavaScript file is
needed: rtl.js. It defines an object rtl. This object will start
the Object Pascal code if you include a call to rtl.run() in
the HTML page. Then we pass the file to the transpiler:
 <script>
 rtl.run();
 </script>
 pas2js can automatically include this file (rtl.js)
in the generated output, like this:
 pas2js -Jc -Jirtl.js -Tbrowser demoradar.lpr
https://raw.githack.com/breitsch2/maXbox4/master/assets/demoradar.html
18 / 22
Content
 The pas2js compiler and RTL are – naturally –
open source and can be downloaded and used
freely. And I got my output as a javasscript file
demoradar.js
 var pas = { $libimports: {}};
 var rtl = {
 version: 20200,
 quiet: false,
 debug_load_units: false,
 debug_rtti: false, $res : {},
Also: https://github.com/Kryuski/pas2js-for-delphi
19 / 22
HTML inline
 <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Example showing how to use TchartJS">
<meta name="author" content="silvioprog">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js" integrity="sha256-
oSgtFCCmHWRPQ/JmR4OoZ3Xke1Pw4v50uh6pLcu+fIc=" crossorigin="anonymous"></script>
<script src="./js/demoradar.js"></script>
 <title>TChartJS example</title>
<style>
.title {
margin: 20px 0 20px 0
}
</style>
</head>
view-source:https://raw.githack.com/breitsch2/maXbox4/master/assets/demoradar.html
20 / 22
Components
 Imageformats: .bmp, .png, .xpm, . jpg, .pnm,
.tga (imagesforlazarus)
 OpenGL Components: lazopenglcontext (gtk,
carbon, win32/64) oder glscene (linux/gtk,
win32, SVG!, https://ideasawakened.com/post/simple-svg-images-in-delphi-applications )
 Internet/smtp/ftp/http/tcp: Synapse, Curl, Indy,
Lnet, TRestclient
 Code-Formater: prettyformat, Charts, Bootstrap
 ...
https://raw.githack.com/breitsch2/maXbox4/master/assets/graph3.html
21 / 22
Project Examples
https://linuxschweizag.wordpress.com/2023/04/06/tutorials/
https://maxbox4.wordpress.com/2023/05/23/mapbox-in-maxbox/
https://raw.githack.com/breitsch2/maXbox4/master/assets/pacman2/pacman.html
https://youtu.be/SC3i7Ru8XPY
https://www.clevercomponents.com/articles/article052/
22 / 22
Pas2JS & JS1Pas
Thanks for coming!
Materials:
https://github.com/breitsch2/maXbox4/tree/master/assets

More Related Content

Similar to Pas2JS Integration: Combine web and desktop development with JavaScript and Pascal

maXbox Starter87
maXbox Starter87maXbox Starter87
maXbox Starter87Max Kleiner
 
Dessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloudDessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloudMassimiliano Dessì
 
Come costruire una Platform As A Service con Docker, Kubernetes Go e Java
Come costruire una Platform As A Service con Docker, Kubernetes Go e JavaCome costruire una Platform As A Service con Docker, Kubernetes Go e Java
Come costruire una Platform As A Service con Docker, Kubernetes Go e JavaCodemotion
 
Evolution of containers to kubernetes
Evolution of containers to kubernetesEvolution of containers to kubernetes
Evolution of containers to kubernetesKrishna-Kumar
 
Docker Athens: Docker Engine Evolution & Containerd Use Cases
Docker Athens: Docker Engine Evolution & Containerd Use CasesDocker Athens: Docker Engine Evolution & Containerd Use Cases
Docker Athens: Docker Engine Evolution & Containerd Use CasesPhil Estes
 
Apache Cassandra and Apche Spark
Apache Cassandra and Apche SparkApache Cassandra and Apche Spark
Apache Cassandra and Apche SparkAlex Thompson
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1Hajime Tazaki
 
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2   Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2 Adil Khan
 
Tutorial to setup OpenStreetMap tileserver with customized boundaries of India
Tutorial to setup OpenStreetMap tileserver with customized boundaries of IndiaTutorial to setup OpenStreetMap tileserver with customized boundaries of India
Tutorial to setup OpenStreetMap tileserver with customized boundaries of IndiaArun Ganesh
 
Introduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 PresentationIntroduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 PresentationKnoldus Inc.
 
What’s new in cas 4.2
What’s new in cas 4.2 What’s new in cas 4.2
What’s new in cas 4.2 Misagh Moayyed
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3kognate
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack IntroductionAnjali Chawla
 
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler CollectionMoabi.com
 
webpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingfwebpack introductionNotice Demystifyingf
webpack introductionNotice DemystifyingfMrVMNair
 

Similar to Pas2JS Integration: Combine web and desktop development with JavaScript and Pascal (20)

Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17
 
maXbox Starter87
maXbox Starter87maXbox Starter87
maXbox Starter87
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 
Dessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloudDessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloud
 
Come costruire una Platform As A Service con Docker, Kubernetes Go e Java
Come costruire una Platform As A Service con Docker, Kubernetes Go e JavaCome costruire una Platform As A Service con Docker, Kubernetes Go e Java
Come costruire una Platform As A Service con Docker, Kubernetes Go e Java
 
Evolution of containers to kubernetes
Evolution of containers to kubernetesEvolution of containers to kubernetes
Evolution of containers to kubernetes
 
Docker Athens: Docker Engine Evolution & Containerd Use Cases
Docker Athens: Docker Engine Evolution & Containerd Use CasesDocker Athens: Docker Engine Evolution & Containerd Use Cases
Docker Athens: Docker Engine Evolution & Containerd Use Cases
 
Apache Cassandra and Apche Spark
Apache Cassandra and Apche SparkApache Cassandra and Apche Spark
Apache Cassandra and Apche Spark
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1
 
Readme
ReadmeReadme
Readme
 
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2   Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 
Tutorial to setup OpenStreetMap tileserver with customized boundaries of India
Tutorial to setup OpenStreetMap tileserver with customized boundaries of IndiaTutorial to setup OpenStreetMap tileserver with customized boundaries of India
Tutorial to setup OpenStreetMap tileserver with customized boundaries of India
 
Introduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 PresentationIntroduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 Presentation
 
What’s new in cas 4.2
What’s new in cas 4.2 What’s new in cas 4.2
What’s new in cas 4.2
 
Book
BookBook
Book
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
Serverless and React
Serverless and ReactServerless and React
Serverless and React
 
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
 
webpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingfwebpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingf
 

Recently uploaded

Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknowmakika9823
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...Suhani Kapoor
 

Recently uploaded (20)

Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
 

Pas2JS Integration: Combine web and desktop development with JavaScript and Pascal

  • 1. 22 Pas2JS Integration Nov. 2023, Max Kleiner  Combine the world of web development with a desktop development world.  IDE / RAD / CLI / Shell / Scripts  Pas2JS and JS1Pas Scripting maXbox4  https://wiki.freepascal.org/pas2js  This session shows you various ways of having JS in your application. maXbox4exe Digital unterschrieben von maXbox4exe Datum: 2023.08.11 23:23:51 +02'00'
  • 2. 2 / 22 Agenda  JS1Pas – JS integrate in Delphi Form  Hybrid Mode as TWebBrowser.  Mapping from JS Lib (ex. unit ChartJS; Pascal mapping for ChartJS: https://www.chartjs.org)  Pas2Js – from pas source to a *.js  Today JS/HTML/CSS/Websockets is a main stack for building frontends and user interfaces. It has great libraries, frameworks and gigantic community.
  • 3. 3 / 22 From J1Pas to Hybrid  No Makefiles: Compiler searches for all required source files and RTL's and automatically recompiles all changed files.  Simple Solution: OpenWeb(JSApp);  Local or Server:  Const JSAPP2 = 'C:Program FilesStreamingIBZ2021Module2_3EKON27text2jstester.html';  Const JSAPP3 = 'https://raw.githack.com/breitsch2/maXbox4/master/assets/text2jstest er.html';
  • 4. 4 / 22 Hybrid Mode  A hybrid application (hybrid app) is one that combines elements of both native and Web applications.  In practice it means that you build native applications with a web stack, engine or node. There are several libraries like Electron or NW.js, but we can also build such applications using Delphi or Lazarus. https://raw.githack.com/breitsch2/maXbox4/master/assets/basicpdf2.html
  • 5. 5 / 22 Hybrid Mode  ScriptGate for ex. is a cool library that allows to call Delphi methods from JS code in TWebBrowser. Also the other way round.  Now I will create a script application and place webbrowser into a form. Then we add some lines of code: WebBrowser1:= TWebBrowser.create(form1); with WebBrowser1 do begin TWinControl(WebBrowser1).Name:= 'MyWebBrowser2JS'; // Parent property is read-only unless cast TWinControl(WebBrowser1).Parent:= form1; https://raw.githack.com/breitsch2/maXbox4/master/assets/text2jstester.html
  • 6. 6 / 22 Be aware of  cFeatureBrowserEmulation =  'MicrosoftInternet ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION';  Late binding possible:  objIE:= CreateOleObject('InternetExplorer.Application');  Silent mode to debug and events: Silent := False;  OnDocumentComplete:= @WebBrowserDocumentComplete; Demo: 1235_Weatherboxsep2023_EKON27_API_JS_Integrate1.txt
  • 7. 7 / 22 API Keys  Where you store Developer-Keys.  Use Read-only keys  These API keys are specifically designed to be used in client-side code. They can only read data from the API, not write to it or change anything. So even someone got a hold of a read-only API key, they couldn't do any damage to your data.
  • 8. 8 / 22 API Key Solution  My preferred solution is to create a config.json file and fetch() config data in Javascript file.  config.json  {  "apiKey": "My read-only API key"  }  script.js  fetch('/config.json').then(function (config) {  console.log('API key:', config.apiKey);  }); Demo: 1241_pixabay_api_tester.pas
  • 9. 9 / 22 Just a Shell  IDE for Console or Terminal
  • 10. 10 / 22 Pas2JS  Pas2js is an open source Pascal to JavaScript transpiler. It parses Object Pascal or maXbox files and emits JScript. It takes Delphi/Lazarus projects and modules (.DPR, .LPR, .PAS, .PP) and converts them to JavaScript (.JS). The JS is currently of level ECMAScript 5 and should run in any browser or in Node.js (target “nodejs”). It is available in 5 forms:  as a library  as a command-line program  as a webserver  as a node.js program  as a program running in the browser.
  • 11. 11 / 22 Using libpas2js.dll  You can build libpas2js.dll directly by using Lazarus or lazbuild to compile  compiler/utils/pas2js/pas2jslib.lpi Anyway you should now have the library:  libpas2js.so on Linux  libpas2js.dynlib on macOS  libpas2js.dll on Windows It simply passes the command line parameters to run the compiler, so it behaves pretty much like the command line compiler pas2js.exe.
  • 12. 12 / 22 Let's compile  It transpiles from actual Pascal source, it has no intermediate .ppu files. That means all sources must always be available.  Const pas2jsPATH = 'C:Program FilesStreamingmaxbox4examplespas2js-windows- 2.2.0pas2js-windows-2.2.0bini386-win32';  writeln(GETDOSOutput('cmd.exe /c "'+  pas2jsPATH+'pas2js" -Jc -Jirtl.js -Tbrowser ....demochartjsdemoradar.lpr', Pas2jsPATH));   Demo: 1238_create_process_etl_javascript.txt
  • 13. 13 / 22 After Transpile  Pas2JS Compiler version 2.2.0 [2022/02/22] for Win32 i386  Copyright (c) 2021 Free Pascal team.  C:Program FilesStreamingmaxbox4examplespas2js- windows-2.2.0pas2js-windows- 2.2.0demochartjsdemotime.lpr(9,3) Hint: Unit "Math" not used in demotime  Info: 9627 lines in 7 files compiled, 0.1 secs   mX4 executed: 11/08/2023 15:21:40 Runtime: 0:0:2.272 Memload: 54% use
  • 14. 14 / 22 Sign Compatability  Simply add the config.json to your .gitignore and treat it the same as you would a .env file.  Sign your script (yes we can, for windows)  TOSIGNFILE:= '1235_tetris_signed.js'  if fileExists(CERTFILE) then begin  writeln(botostr(ChDirW(TOOLPATH)));  passfromfile:= FileToString('./certs/passfile2.txt')  ExecuteShell('signtool.exe', 'sign /f'  +' certs/maxbox4exe.pfx /p '+passfromfile  +' /t http://timestamp.digicert.com '+TOSIGNFILE);
  • 15. 15 / 22 pas2js Electron Web App  Install Electron and you must install node.js.  Windows, MacOS: https://nodejs.org/en/download/  Debian, Ubuntu:  Check that node and npm work:  node -v  npm -v  C:boxmynodejsnode_moduleselectrondistelectron.exe https://wiki.freepascal.org/pas2js_Electron_Web_Application
  • 16. 16 / 22 Class Definitions Through external class definitions, the trans/compiler can use JavaScript classes:  All classes available in the JavaScript runtime, and in the browser are available  through import units (comparable to the windows or Unix units for the native compiler).  For Node.js, basic support for the nodejs runtime environment is available.  An import unit for jQuery is available (libjquery)  a converter from maXbox to lpr project files
  • 17. 17 / 22 Distribution  For the generated code to work, a small JavaScript file is needed: rtl.js. It defines an object rtl. This object will start the Object Pascal code if you include a call to rtl.run() in the HTML page. Then we pass the file to the transpiler:  <script>  rtl.run();  </script>  pas2js can automatically include this file (rtl.js) in the generated output, like this:  pas2js -Jc -Jirtl.js -Tbrowser demoradar.lpr https://raw.githack.com/breitsch2/maXbox4/master/assets/demoradar.html
  • 18. 18 / 22 Content  The pas2js compiler and RTL are – naturally – open source and can be downloaded and used freely. And I got my output as a javasscript file demoradar.js  var pas = { $libimports: {}};  var rtl = {  version: 20200,  quiet: false,  debug_load_units: false,  debug_rtti: false, $res : {}, Also: https://github.com/Kryuski/pas2js-for-delphi
  • 19. 19 / 22 HTML inline  <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content="Example showing how to use TchartJS"> <meta name="author" content="silvioprog"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js" integrity="sha256- oSgtFCCmHWRPQ/JmR4OoZ3Xke1Pw4v50uh6pLcu+fIc=" crossorigin="anonymous"></script> <script src="./js/demoradar.js"></script>  <title>TChartJS example</title> <style> .title { margin: 20px 0 20px 0 } </style> </head> view-source:https://raw.githack.com/breitsch2/maXbox4/master/assets/demoradar.html
  • 20. 20 / 22 Components  Imageformats: .bmp, .png, .xpm, . jpg, .pnm, .tga (imagesforlazarus)  OpenGL Components: lazopenglcontext (gtk, carbon, win32/64) oder glscene (linux/gtk, win32, SVG!, https://ideasawakened.com/post/simple-svg-images-in-delphi-applications )  Internet/smtp/ftp/http/tcp: Synapse, Curl, Indy, Lnet, TRestclient  Code-Formater: prettyformat, Charts, Bootstrap  ... https://raw.githack.com/breitsch2/maXbox4/master/assets/graph3.html
  • 21. 21 / 22 Project Examples https://linuxschweizag.wordpress.com/2023/04/06/tutorials/ https://maxbox4.wordpress.com/2023/05/23/mapbox-in-maxbox/ https://raw.githack.com/breitsch2/maXbox4/master/assets/pacman2/pacman.html https://youtu.be/SC3i7Ru8XPY https://www.clevercomponents.com/articles/article052/
  • 22. 22 / 22 Pas2JS & JS1Pas Thanks for coming! Materials: https://github.com/breitsch2/maXbox4/tree/master/assets