SlideShare a Scribd company logo
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 EKON27_Pas2JS_sign.pdf

Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17
Excelian | Luxoft Financial Services
 
maXbox Starter87
maXbox Starter87maXbox Starter87
maXbox Starter87
Max Kleiner
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
rani marri
 
Dessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloudDessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloud
Massimiliano 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 Java
Codemotion
 
Evolution of containers to kubernetes
Evolution of containers to kubernetesEvolution of containers to kubernetes
Evolution of containers to kubernetes
Krishna-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 Cases
Phil Estes
 
Apache Cassandra and Apche Spark
Apache Cassandra and Apche SparkApache Cassandra and Apche Spark
Apache Cassandra and Apche Spark
Alex 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.1
Hajime Tazaki
 
Readme
ReadmeReadme
Readme
rec2006
 
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 India
Arun Ganesh
 
Introduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 PresentationIntroduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 Presentation
Knoldus 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
 
Book
BookBook
Book
luis_lmro
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
kognate
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
Anjali Chawla
 
Serverless and React
Serverless and ReactServerless and React
Serverless and React
Marina Miranovich
 
[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
Moabi.com
 
webpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingfwebpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingf
MrVMNair
 

Similar to EKON27_Pas2JS_sign.pdf (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

Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
Vineet
 
社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .
NABLAS株式会社
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
Cell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docxCell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docx
vasanthatpuram
 
UofT毕业证如何办理
UofT毕业证如何办理UofT毕业证如何办理
UofT毕业证如何办理
exukyp
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
bopyb
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
Timothy Spann
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
Sachin Paul
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
Márton Kodok
 
writing report business partner b1+ .pdf
writing report business partner b1+ .pdfwriting report business partner b1+ .pdf
writing report business partner b1+ .pdf
VyNguyen709676
 
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理 原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
tzu5xla
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
hyfjgavov
 
Jio cinema Retention & Engagement Strategy.pdf
Jio cinema Retention & Engagement Strategy.pdfJio cinema Retention & Engagement Strategy.pdf
Jio cinema Retention & Engagement Strategy.pdf
inaya7568
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
jitskeb
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
SaffaIbrahim1
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Aggregage
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
1tyxnjpia
 
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Kaxil Naik
 
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
slg6lamcq
 

Recently uploaded (20)

Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
 
社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
Cell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docxCell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docx
 
UofT毕业证如何办理
UofT毕业证如何办理UofT毕业证如何办理
UofT毕业证如何办理
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
 
writing report business partner b1+ .pdf
writing report business partner b1+ .pdfwriting report business partner b1+ .pdf
writing report business partner b1+ .pdf
 
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理 原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
 
Jio cinema Retention & Engagement Strategy.pdf
Jio cinema Retention & Engagement Strategy.pdfJio cinema Retention & Engagement Strategy.pdf
Jio cinema Retention & Engagement Strategy.pdf
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
 
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
 
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
 

EKON27_Pas2JS_sign.pdf

  • 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