Subj : Re: Delphi developers: Simplified use of engine To : netscape.public.mozilla.jseng From : "Sterling Bates" Date : Tue Jul 15 2003 12:41 pm For anyone who downloaded the incorrect version of this file, it's been updated with the correct version. Sorry for the mixup. "Sterling Bates" wrote in message news:bf17l8$co4@ripley.netscape.com... > I spent some time last night writing up a basic class wrapper (you'll need > the jsdecl.pas file as well): > > http://www.sterlingbates.com/delphi/jsclass.zip > http://www.sterlingbates.com/delphi/jsdecl.zip > > It's pretty basic, but you can do the following: > > procedure jsTest; > var > eng: TJSEngine; > s: String; > begin > eng := TJSEngine.Create; > try > eng.Evaluate('function doSomething() { return "hello"; }',nil); > eng.Call('doSomething',nil,[],s); > ShowMessage('doSomething() returned: ' +s); > finally > eng.Free; > end; > end; > > You can pass arguments to the functions, too: > > procedure jsTest; > var > eng: TJSEngine; > param: Integer; > num: Integer; > s: String; > jsstr: PJSString; > begin > eng := TJSEngine.Create; > try > eng.Evaluate('function doSomething(p_str) { return "Hello, > "+p_str; }',nil); > eng.Evaluate('function doMath(p_num) { return p_num*6; }',nil); > > param := eng.Declare(3); > eng.Call('doMath',nil,[param],num); > > jsstr := eng.Declare('Your Name Here'); > eng.Call('doSomething',nil,[JSStringToJSVal(str)],s); > > ShowMessage('doSomething() returned: ' +s +#10'doMath() returned > '+IntToStr(num)); > finally > eng.Free; > end; > end; > > Real help is possibly forthcoming, but unless I get enough requests I don't > have the time right now. Happy coding! > > Sterling > > .