Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


What's DelphiScript ?Go to Max Kleiner's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Short Overview to PascalScript and similiar interpreters
Product:
Delphi all versions
Category:
Object Pascal
Skill Level:
Scoring:
Last Update:
01/08/2009
Search Keys:
delphi delphi3000 article borland vcl code-snippet scripting scriptrecorder delphiscript pascalscript maxbox
Times Scored:
8
Visits:
8393
Uploader: Max Kleiner
Company: kleiner kommunikation
Reference: http://www.softwareschule.ch/maxbox.htm
 
Question/Problem/Abstract:
There are tools which support DelphiScript or PascalScript. Or other tools are interpreter which implement sort of pascal-scripting. What's the aim of these tools and where you can find it.
Answer:



************************************
Notice about maXbox
************************************

maXbox is a scripter tool with an inbuild delphi engine in one exe! It is designed for teaching, test and analyzing methods and algorithms and runs under Win and Linux (CLX) to build Delphi in a box. maXbox is based on RemObjects Pascal Script, the smart evolution of programming.  Now in Version 2.5 with include-file, event handler, printing, drag n' drop and DLL support.

http://www.softwareschule.ch/maxbox.htm

MaXbox and PascalScript is an interpreter of a vast subset of the OP (ObjectPascal) language which supports all OP data types except interfaces.
This subset was extended by the Poly data type that allows you to operate with dynamic data structures (lists, trees, and more) without using pointers and apply Pascal language in the Artificial Intelligence data domain with the same success.


Important First Steps:
----------------------------
1. You can load a script by open the file.
2. Then you can compile or save the file.
3. When using the menu options/show_linenumbers the editor is in read only mode!
4. The output window is object memo2 from TMemo.
5. Last file and window are saved in a ini file.
6. By escape esc you can close the box.
7. The source in the zip is not complete, please contact for further source.


Maybe you have noticed, that I put the article in the Object Pascal category but I could also put it in the OLE category. So in a short way, DelphiScript is an OLE scripting language, like VBScript or JScript. Depending on the history, the language root is Standard Pascal and not ObjectPascal.

Extensions
----------
There are extensions which supports OLE objects and the OLE variant type. It then deals with all Standard Pascal types as OLEVariant, or it does support them, e.g. not supported are pointers (of course), files, set operators (replaced with procedures), records (but records are replaced by untyped arrays). Therfore you can declare the type of a variable or parameter, it is allowed, but has no effect. Another extension supports exception handling the same way as OPascal does.
Bref, all variables are of the OleVariant type.

Comparison
-----------------
Delphi Script and VBScript are case insensitive while JavaScript is case sensitive.
Delphi Script is strongly typed while VBScript and JavaScript is loosely typed. This means variable declaration is mandatory in Delphi Script, but variable declaration is not needed in VBScript and JavaScript.
Delphi Script uses square brackets to access data property and round brackets for function calls. VBScripts and JavaScript do not make this distinction. For example, the following statements are equivalent:
(Delphi Script) sum := Data1.Value[0] + tq_min(Data2.Value[0],0);
(VBScript) sum = Data1.Value(0) + tq_min(Data2.Value(0),0)
(JavaScript) sum = Data1.value(0) + tq_min(Data2.Value(0),0);

A Tool Example
--------------
The easiest way to begin scripting is to use a recorder. Later you can edit the script and so on. For example DelphiScript support is built into AQTest:
www.automatedqa.com
It's a highly recommended tool that comes out of the box with 19 profilers.  The two that we are interested in most, is "listing unused units", and "identifying who calls what method" are included. (The method call profiler display its info through a diagram. fantastic cool.;)
So let's get back to DelphiScript(DS) or PascalScript (PS). DS or PS code can be read by Delphi.
DS supports almost all Standard Pascal operators and routines, minus those that deal with type conversion or I/O, type conversion are always implicit.
Interesting is, there are units. But as DS is meant for scripting and selfstanding routines, units are simply groupings of scripts in one file. That means, no unit structure (interface, implementation etc.) is possible.

  
1. Concrete Implementation Dream Scripter
------------------------------------------
Dream Scripter supports Delphi Script language - the subset of Object Pascal. Before execution the script is compiled to native processor code and that's why Delphi Script is much faster than other scripting languages. Another cool feature - you don't need to have any scripting engine or extra DLLs on the user computer to use Delphi Script.  

Dream Scripter is written entirely with Delphi. You don't need any extra DLLs or OCXs. Source is compatible and tested with Delphi 3, Delphi 4, Delphi 5, C++ Builder 3, C++ Builder 4, and C++ Builder 5

We are very happy to announce the release of the first version of our very popular Dream Scripter for Delphi 6 (CLX) and Kylix too.

The most exciting feature of Dream Scripter: you can use any object, function, or variable you have in your Delphi source within your scripts. Thanks to the import program that comes with Dream Scripter. It analyzes your sources and generates import files. Just add the resulting units to your project uses section and you can use everything that was declared in the source units. We provide imported files for all VCL units so you can use VCL in your scripts right away.


www.dream-com.com


2. Concrete Implementation PascalScript
------------------------------------------

We are happy to announce that Carlo Kok (formerly Innerfuse PascalScript) has joined RemObjects Software, and that as of today PascalScript has been merged and improved into the product line of RemObjects Software, Inc.

PascalScript (PS) has a bright future, e.g:
With the release of V0.845 of X-Force, which will be soon available, there will be extensive changes in the script language X-Script. The special for X-Force developed script language will be replaced by the extensive and flexible Pascal Script by Carlo Kok (www.remobjects.com).  
With only one code line you can import an excisting Delphi function in PS and could be called from there. PS supports the direct interaction with Delphi objects and Delphi records so that the expansion will be easier in the future.

PS is a free scripting engine that allows you to use most of the ObjectPascal language within your Delphi projects at runtime. Written completely in Delphi, it's composed of a set of units that can be compiled into your executable, eliminating the need to distribute any external files.
The script engine never calls Application.ProcessMessages by itself, so your application may hang, while the script is running.
To use the component version of PS, you must first place it on your form or data module, set or assign the script property, call the compile method and call the execute method.
A scripting engine allows an end user to customize an application to his or her needs without having to recompile it. In addition, you can update your applications by just sending a new script file.

http://www.remobjects.com

Short example of how to use it:
Maybe you want to set a script which you can change at runtime like this:

program ScriptTest;
// first interpreter of runmax
var i,a: byte;

begin
  for i:= 1 to 10 do begin
    a:= random(150);
    writeln(inttostr(a));
  end
end.

Next you have to register functions like random or writeln in your exe:

function myrandom(const a: byte): byte;
begin
  result:= random(a);
end;

procedure MyWriteln(const s: string);
begin
  Form1.Memo2.Lines.Add(s);
end;

procedure TForm1.PSScriptCompile(Sender: TPSScript);
begin
  Sender.AddFunction(@MyWriteln, 'procedure Writeln(s: string);');
  Sender.AddFunction(@myrandom, 'function random(const a: byte): byte');
  Sender.AddRegisteredVariable('Application', 'TApplication');
  Sender.AddRegisteredVariable('Self', 'TForm');
  Sender.AddRegisteredVariable('Memo1', 'TMemo');
  Sender.AddRegisteredVariable('Memo2', 'TMemo');
end;

The rest to compile and execute in a demo called /Samples/TestApp is available on http://www.remobjects.com/articles/


3. Conrete Implementation PasScript
-----------------------------------------
PasScript is an interpreter of a vast subset of the OP (ObjectPascal) language which supports all OP data types except interfaces.
This subset was extended by the Poly data type that allows you to operate with dynamic data structures (lists, trees, and more) without using pointers and apply Pascal language in the Artificial Intelligence data domain with the same success.
PasScript supports more wide subset of the OP language. You can use such concepts as units, default parameters, overloaded routines, open arrays, records, sets, pointers, classes, objects, class references, events, exceptions, and more in a script. PasScript syntax is 100% compatible with OP.
All calling conventions register, pascal, stdcall, cdecl, safecall are supported Script-defined handlers for Windows messages Script-defined callback functions.
For example, you can define WindowProc function directly in a script More flexible importing Delphi classes. You can use instances of any Delphi class in a script create new instances of a Delphi class in a script and destroy them create new PasScript class in a script which inherits a Delphi class. More wide possibilities regarding the event handlers. You can create script-defined event handler for Delphi defined event and vice versa. You can pause, resume and terminate scripts and PasScript allows you to control an OLE Automation server.
The TPasScript component allows you to embed the interpreter into your Delphi, Kylix or C++ Builder application, so you can extend and customize the application without having to recompile it.
http://users.ints.net/virtlabor/passcript/


4. Conrete Implementation DelphiScript in ASP.NET
--------------------------------------------------
One of the latest invention is to use OP as a script language for ASP.NET:
Recognizing Delphi as a script language works like this:
The first step in getting support for ASP.NET is making sure it recognizes Delphi as a scripting language, and knows how to invoke the Delphi for .NET compiler for the various ASP file types.
ASP.NET will look for a web.config file in the root of whatever virtual directories you set up for IIS. Here are the contents of this file for using Delphi as a scripting language with ASP.NET.
The first step in getting support for ASP.NET is making sure it recognizes Delphi as a scripting language, and knows how to invoke the Delphi for .NET compiler for the various ASP file types.

ASP.NET will look for a web.config file in the root of whatever virtual directories you set up for IIS. Here are the contents of this file for using Delphi as a scripting language with ASP.NET.


configuration
  system.web                            
    compilation debug="true"
       assemblies
          add assembly="DelphiProvider" /
       assemblies
       compilers
          compiler language="Delphi" extension=".pas"
            type="Borland.Delphi.DelphiCodeProvider,DelphiProvider" /  
       compilers
    compilation
  system.web
configuration

more on that on:
http://bdn.borland.com/article/0,1410,28974,00.html






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
RE: DelphiScript
    art navasardyan (May 10 2001 3:54PM)

Hi there,
I found your article very interesting. The reason being, we use a lot of OLE Automation stuff (our main EndOfDay script is written in VBScript), so we (as proud Delphi developers) would be very keen to learn more on DelphiScript. Are you likely to continue your installments on this subject? What other practical sites that expand on DelphiScript in more detail could you recommend? Thank you.
Respond

RE: RE: DelphiScript
Peter Morris (May 11 2001 9:53AM)

look at www.dream-com.com

They have a native OPascal script componenent.  It even compiles for extra speed and allows you to write full units (it resolves other units in the USES clause too).

Looks pretty good !
Respond

RE: RE: DelphiScript
Max Kleiner (May 16 2001 7:30AM)

Yeah, I'll continue with this so we have been testing a ds-component, it's called Dream Scripter:
http://soarowl.top263.net/en/othervcl.html
This component can support JavaScript and DelphiScript. Use it you can control all components in your program.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. Irigoyen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)