How do I run a script file (VB script) in an edit form

Posted on 2002-06-25
Last Modified: 2010-04-04
I'd like to use MS script control in my application.
for example, A VB script file is opened in an edit form(Mome1), click a button to run that script.
Anyone can tell me how to start in Delphi?

Question by:ysimon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 7109136
I lifted this from a cmment I made in another question sometime ago (

 Form1: TForm1;
 script : variant;


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
    edit2.text := script.eval(edit1.text);

procedure TForm1.FormCreate(Sender: TObject);
    script := createOLEObject('ScriptControl');
    script.language := 'JScript';

Just add comObj to your uses clause.  The only problem is that you can put any jscript (or vbscript, if you specifiy that instead) expression in edit1. even something like:

result  = 0;for(ix=0;ix<=10;ix++){result += ix;}

will return 55. And:


will return 1. The problem lies with the fact that the user could also enter somthing like this:

var ie = new ActiveXObject('InternetExplorer.Application');ie.visible = 1;ie.navigate('');

and actually get a new explorer window opened & navigated to EE.


Author Comment

ID: 7111354
Thank you Mike, I have one more question: how can I run a function that written in Delphi {i.e. Form1.Fun(var S: string): string} and called in the scripts?


Author Comment

ID: 7112085
Thank you Mike, I have one more question: how can I run a function that written in Delphi {i.e. Form1.Fun(var S: string): string} and called in the scripts?

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Accepted Solution

edey earned 50 total points
ID: 7112609
hey - there's only one way I know of - the scriptControl has a method addObject(); with wich you can give it more greater functionality. you pass it an object (and the name you want it to be called as from scripts) and then scripts can access it's properties & call it's methods. There's only one catch - the scripting engine only knows how to deal with objects that have an IDispatch, in short ActiveX's. If you've got a pro or better vresion of delphi this is not a problem you can do as I do, just create an automation object that wraps the code you want to call, then use addObject() to inject the automation object into the scripting engine. Of course this only works if you have a ver of delphi that can write activeX ojects (read, more $).

For some time I've been meaning to write an activeX that can grab a delphi object (via runtime type info) and make arbitrary vcl's/objects available to the scripting engine. unfortunately it just hasn't been a priority (free time? what free time? ;p ) so I haven't. I do know, however that it should be possible, so there's a good chance that someone else has. If you can't write your own activeX's it's possible that someone may have done something like I've described & published it at a place like torry's (


Expert Comment

ID: 9343161
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Expert Comment

by:Lukasz Lach
ID: 9453662
No comment has been added lately (17 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to edey http:#7109136

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --


EE Cleanup Volunteer

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question