Solved

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

Posted on 2002-06-25
6
175 Views
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?

ysimon
0
Comment
Question by:ysimon
[X]
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
6 Comments
 
LVL 6

Expert Comment

by:edey
ID: 7109136
I lifted this from a cmment I made in another question sometime ago (http://www.experts-exchange.com/questions/Q_20186201.html):

var
 Form1: TForm1;
 script : variant;

implementation

{$R *.dfm}

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

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


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:

2*Math.sin(45*3.1415926535897932384/180)/Math.sqrt(2);

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('www.experts-exchange.com');

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

GL
Mike
0
 

Author Comment

by:ysimon
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?

ysimon
0
 

Author Comment

by:ysimon
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?

ysimon
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
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 (http://www.torry.net).

GL
Mike
0
 

Expert Comment

by:CleanupPing
ID: 9343161
ysimon:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9453662
ysimon,
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 ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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