<div dir="ltr"><div class="gmail_extra">Okay great. Thanks for the information. I'll experiment with the smart pointers and their potential performance impact. In the interim I've created a solution using the approach of records containing private reference counted interfaces. Here is an example of my JSContext record:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><ol style="color:rgb(0,0,0);font-family:monospace;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:-webkit-left;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  JSContext<span> </span><span style="color:rgb(0,0,102)">=</span><span> </span><span style="color:rgb(0,0,102);font-weight:bold">record</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"> <span> </span><span style="color:rgb(0,0,0);font-weight:bold">private</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">    FRef<span style="color:rgb(0,0,102)">:</span><span> </span>IJSContext<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"> <span> </span><span style="color:rgb(0,0,0);font-weight:bold">public</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">    class<span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>Create<span style="color:rgb(0,0,102)">:</span><span> </span>JSContext<span style="color:rgb(0,0,102)">;</span><span> </span>static<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">    class<span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>Retain<span style="color:rgb(0,153,0)">(</span>C<span style="color:rgb(0,0,102)">:</span><span> </span>JSContextRef<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSContext<span style="color:rgb(0,0,102)">;</span><span> </span>static<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">    class operator Implicit<span style="color:rgb(0,153,0)">(</span>C<span style="color:rgb(0,0,102)">:</span><span> </span>JSContext<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSContextRef<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>EvaluateScript<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,0,0);font-weight:bold">const</span><span> </span>Script<span style="color:rgb(0,0,102)">:</span><span> </span><span style="color:rgb(0,0,102);font-weight:bold">string</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>CreateFunction<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,0,0);font-weight:bold">const</span><span> </span><span style="color:rgb(0,0,0);font-weight:bold">Name</span><span style="color:rgb(0,0,102)">:</span><span> </span><span style="color:rgb(0,0,102);font-weight:bold">string</span><span style="color:rgb(0,0,102)">;</span><span> </span>Callback<span style="color:rgb(0,0,102)">:</span><span> </span>JSFunction<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSObject<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>CreateMethod<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,0,0);font-weight:bold">const</span><span> </span><span style="color:rgb(0,0,0);font-weight:bold">Name</span><span style="color:rgb(0,0,102)">:</span><span> </span><span style="color:rgb(0,0,102);font-weight:bold">string</span><span style="color:rgb(0,0,102)">;</span><span> </span>Callback<span style="color:rgb(0,0,102)">:</span><span> </span>JSMethod<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSObject<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>CreateUndefined<span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>CreateNull<span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>CreateBoolean<span style="color:rgb(0,153,0)">(</span>Value<span style="color:rgb(0,0,102)">:</span><span> </span><span style="color:rgb(0,0,102);font-weight:bold">Boolean</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>CreateNumber<span style="color:rgb(0,153,0)">(</span>Value<span style="color:rgb(0,0,102)">:</span><span> </span>Double<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>CreateString<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,0,0);font-weight:bold">const</span><span> </span>Value<span style="color:rgb(0,0,102)">:</span><span> </span><span style="color:rgb(0,0,102);font-weight:bold">string</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>CreateJSON<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,0,0);font-weight:bold">const</span><span> </span>Value<span style="color:rgb(0,0,102)">:</span><span> </span><span style="color:rgb(0,0,102);font-weight:bold">string</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"> <span> </span><span style="color:rgb(0,0,0);font-weight:bold">end</span><span style="color:rgb(0,0,102)">;</span></div></li></ol>So you could use it to embed a javascript engine in your free pascal application like so:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><ol style="color:rgb(0,0,0);font-family:monospace;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:-webkit-left;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>TestCallback<span style="color:rgb(0,153,0)">(</span>Context<span style="color:rgb(0,0,102)">:</span><span> </span>JSContext<span style="color:rgb(0,0,102)">;</span><span> </span>Args<span style="color:rgb(0,0,102)">:</span><span> </span>JSValues<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">begin</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  Result<span> </span><span style="color:rgb(0,0,102)">:</span><span style="color:rgb(0,0,102)">=</span><span> </span>JSContext<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">CreateString</span><span style="color:rgb(0,153,0)">(</span><span style="color:rgb(255,0,0)">'You passed '</span><span> </span><span style="color:rgb(0,0,102)">+</span><span> </span>IntToStr<span style="color:rgb(0,153,0)">(</span>Args<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">Length</span><span style="color:rgb(0,153,0)">)</span><span> </span><span style="color:rgb(0,0,102)">+</span><span> </span><span style="color:rgb(255,0,0)">' arguments'</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">end</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"> </div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">function</span><span> </span>MessageBoxCallback<span style="color:rgb(0,153,0)">(</span>Context<span style="color:rgb(0,0,102)">:</span><span> </span>JSContext<span style="color:rgb(0,0,102)">;</span><span> </span>Args<span style="color:rgb(0,0,102)">:</span><span> </span>JSValues<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">begin</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"> <span> </span><span style="color:rgb(0,0,0);font-weight:bold">if</span><span> </span>Args<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">Length</span><span> </span>><span> </span><span style="color:rgb(204,102,204)">0</span><span> </span><span style="color:rgb(0,0,0);font-weight:bold">then</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">    ShowMessage<span style="color:rgb(0,153,0)">(</span>Args<span style="color:rgb(0,153,0)">[</span><span style="color:rgb(204,102,204)">0</span><span style="color:rgb(0,153,0)">]</span><span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">AsString</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  Result<span> </span><span style="color:rgb(0,0,102)">:</span><span style="color:rgb(0,0,102)">=</span><span> </span>JSContext<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">CreateUndefined</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">end</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"> </div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">procedure</span><span> </span>TForm1<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">Button1Click</span><span style="color:rgb(0,153,0)">(</span>Sender<span style="color:rgb(0,0,102)">:</span><span> </span>TObject<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">var</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  C<span style="color:rgb(0,0,102)">:</span><span> </span>JSContext<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  R<span style="color:rgb(0,0,102)">:</span><span> </span>JSValue<span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">begin</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  C<span> </span><span style="color:rgb(0,0,102)">:</span><span style="color:rgb(0,0,102)">=</span><span> </span>JSContext<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">Create</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  C<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">CreateFunction</span><span style="color:rgb(0,153,0)">(</span><span style="color:rgb(255,0,0)">'test'</span><span style="color:rgb(0,0,102)">,</span><span> </span>TestCallback<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  C<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">CreateFunction</span><span style="color:rgb(0,153,0)">(</span><span style="color:rgb(255,0,0)">'messageBox'</span><span style="color:rgb(0,0,102)">,</span><span> </span>MessageBoxCallback<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  R<span> </span><span style="color:rgb(0,0,102)">:</span><span style="color:rgb(0,0,102)">=</span><span> </span>C<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">ExecuteScript</span><span style="color:rgb(0,153,0)">(</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(255,0,0)">'let s = test(123, "hello");'</span><span> </span><span style="color:rgb(0,0,102)">+</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(255,0,0)">'messageBox("test gave us:" + s);'</span><span> </span><span style="color:rgb(0,0,102)">+</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">   <span> </span><span style="color:rgb(255,0,0)">'let result = "okay, we are done.";'</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top">  Caption<span> </span><span style="color:rgb(0,0,102)">:</span><span style="color:rgb(0,0,102)">=</span><span> </span>R<span style="color:rgb(0,0,102)">.</span><span style="color:rgb(0,102,0)">AsString</span><span style="color:rgb(0,0,102)">;</span></div></li><li style="white-space:nowrap;padding:0px 5px;background-color:rgb(255,255,255);line-height:16px;border-left:1px solid rgb(153,153,153)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1em;line-height:1.2em;font-family:monospace;margin:0px;padding:0px;background:none;vertical-align:top"><span style="color:rgb(0,0,0);font-weight:bold">end</span><span style="color:rgb(0,0,102)">;</span></div></li></ol>Note, using my records with interfaces we don't have to clean up anything, and the javascript context is destroyed when Button1Click exits. The only problem I have right now is you cannot forward declare records, so with pascal it's not possible for two records to use each other in their type definitions.</div></div>