Platforms to show: All Mac Windows Linux Cross-Platform

/Tools/JavaScript/JavaScript Engine


Required plugins for this example: MBS Tools Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/JavaScript/JavaScript Engine

This example is the version from Sun, 7th Dec 2019.

Project "JavaScript Engine.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub DoubleClick() MsgBox me.Cell(me.ListIndex,0) End EventHandler
End Control
Control InputText Inherits TextArea
ControlInstance InputText Inherits TextArea
End Control
Control EvalButton Inherits PushButton
ControlInstance EvalButton Inherits PushButton
EventHandler Sub Action() Try Dim s As String = je.EvaluateToString(InputText.Text) List.AppendRow s Catch j As JavaScriptEngineExceptionMBS List.AppendRow "Exception: "+j.Message End Try End EventHandler
End Control
EventHandler Sub Open() je = New MyJavaScriptEngineMBS je.list = List // register a custom function je.RegisterFunction "MessageBox", AddressOf MessageBox, 1, Nil // define a function in JavaScript je.AddFunction "Add", "function (x,y) { return x+y; }" End EventHandler
Function MessageBox(Name as String, Params() as Variant, tag as Variant) As Variant // custom function called from JavaScript If params.Ubound >= 0 Then MsgBox params(0) End If End Function
Property je As MyJavaScriptEngineMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyJavaScriptEngineMBS Inherits JavaScriptEngineMBS
EventHandler Function Input(values() as Variant) As Variant // maybe show dialog here? // or pick values from RecordSet? Return "OK" End EventHandler
EventHandler Sub Print(values() as Variant) For Each v As Variant In values list.AddRow v.StringValue Next End EventHandler
Property list As listbox
End Class
Module Module1
Sub AppendRow(extends l as listbox, s as string) l.AddRow s l.ScrollPosition = l.ListCount // go to end End Sub
End Module
End Project

See also:

The items on this page are in the following plugins: MBS Tools Plugin.


The biggest plugin in space...