Call Javascript in Delphi (2)

Source: Internet
Author: User
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
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.