Solved

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

Posted on 2002-06-25
6
165 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

12 Experts available now in Live!

Get 1:1 Help Now