In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; button1: tbutton; edit1: tedit; label1: tlabel; Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses comobj; {This function requires support from comobj units} {the jscode parameter is the js code to be executed; the jsvar parameter is the variable to be returned} function runjs (const jscode, jsvar: string): string; var Script: olevariant; begin try Script: = createoleobject ('scriptcontrol'); script. language: = 'javascript '; script. executestatement (jscode); Result: = script. eval (jsvar); doesn t result: = ''; end; Procedure tform1.button1click (Sender: tobject); var S: string; begin S: = runjs (memo1.text, 'str'); showmessage (s); end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 167 clientwidth = 244 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesktopcenter pixelsperinch = 96 textheight = 13 object label1: tlabel left = 10 top = 140 width = 72 Height = 13 caption = #35201 #36820 #22238 #30340 #21464 #37327 end object memo1: tmemo left = 0 Top = 0 width = 244 Height = 121 align = altop font. charset = default_charset font. color = clwindowtext font. height =-13 font. name = 'courier new' font. style = [] lines. strings = ('memo1') parentfont = false scrollbars = ssboth taborder = 0 explicitwidth = 323 end object button1: tbutton left = 159 Top = 134 width = 75 Height = 25 caption = #25191 #34892 #20195 #30721 taborder = 1 onclick = button1click end object edit1: tedit left = 85 Top = 136 width = 61 Height = 21 taborder = 2 text = 'str' endend