Solved

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

Posted on 2002-06-25
6
166 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now