首先关联文件
uses Comobj;
----------------------------------------------------------------------------
用来实践的JavaScript
function getTime(){ var d, s = ""; var c = ""; d = new Date(); s += d.getYear()+c; s += (d.getMonth() + 1) + c; s += d.getDate() + c; s += d.getHours() + c; s += d.getMinutes() + c; s += d.getSeconds() + c; s += d.getMilliseconds(); return s; }
----------------------------------------------------------------------------
Delphi 调用JavaScript的代码:
procedure TForm6.Button2Click(Sender: TObject); var js: OleVariant; str: string; begin js := CreateOleObject('ScriptControl'); // 创建组件 js.Language := 'JavaScript'; // 指定组件所使用的语言,也可以是VBScript js.AddCode(Memo1.Text); // 加入JS代码,如上面的代码 str := js.Eval('getTime()');// getTime() function from JS ShowMessage(str); end;