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

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?

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.


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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 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