Script Wizard

Script Wizard

Script Wizard provides scripting support of dynamic Pascal compiling and execution in IDE by RemObjects Pascal Script, including Script Window and Script Library. Script items can be called in menu item or triggered by some Events.

Script Window

Users can use IDE Edit Window to edit a Pascal script file and use Script Window to compile and run it. The window contains toolbar and messages area. It is as below:

- New a Script: New a script outline in IDE Edit Window for writting.

- Load from File: Browse and open a Pascal file in IDE Edit Window.

- Add to Script Library: Add current script to the list of Script Library.

- Show Script Library: Show Script Library Window.

- Compile Script: Compile the source file in current IDE Edit Window. Messages will be printed in messages area below.

- Run Script: Compile and run the source file in current IDE Edit Window.

- Help: Show this Help or Show PSDecl/PSDemo content from drop down menu.

- Close: Close Script Window.

Script Library

Script Library allows user to manage sripts files and settings. Script items are shown in Script Wizard menu item. The Script Library window contains toolbar, script list and script item area. It is as below:

- Add: Add a new script item to edit.

- Delete: Delete selected script item.

- Clear: Clear list. Delete all script items.

- Import from File: Import script items from XML file.

- Export to File: Export script items and save them to a XML file.

- Move Up: Move selected script item up.

- Move Down: Move selected script item down.

- Help: Show this Help.

- Close: Close Script Library Window.

- Name: The name of script item that displayed in menu and script list.

- Desc: Description of script item.

- Filename: The script file name of this script item.

- Icon: Icon displayed in menu item. If no icon specified, no icon displayed.

- Shortcut: Shortcut to execute the script item.

- Script Enabled: Whether the script is enabled to run, compile or triggered.

- Confirm when Manual Run: Whether need confirmation when executing script item maually. It does not affecet the scripts run by events.

- Select Events: You can select the IDE triggers/events in the treeview to run current script item.

  - smManual: Called manually.

  - smIDELoaded: Event after IDE starting.

  - smBeforeCompile: Event before compiling.

  - smAfterCompile: Event after compiling.

  - smFileNotify: Event of File operations, include below:

  - ofnFileOpening: Event of opening a file.

  - ofnFileOpened: Event after opening a file.

  - ofnFileClosing: Event of closing a file.

  - ofnDefaultDesktopLoad: Event of default desktop settings load.

  - ofnDefaultDesktopSave: Event of default desktop settings save.

  - ofnProjectDesktopLoad: Event of current project desktop settings load.

  - ofnProjectDesktopSave: Event of current project desktop settings save.

  - ofnPackageInstalled: Event after a package installed.

  - ofnPackageUninstalled: Event after a package uninstalled.

  - smSourceEditorNotify: Event of Source Editor operations, include below:

    - setOpened: Event after a source editor open a file.

    - setClosing: Event before a source editor close a file.

    - setModified: Event when a source editor modified.

    - setEditViewInsert: Event when create an EditView and insert it into a source editor.

    - setEditViewRemove: Event when remove an EditView from a source editor.

    - setEditViewActivated: Event when activate an EditView in source editor.

  - smFormEditorNotify: Event of Form Editor operations, include below:

    - fetOpened: Event after a form editor open a form file.

    - fetClosing: Event before a form editor close a form file.

    - fetModified: Event when a form editor modified.

    - fetActivated: Event when a form editor activated.

    - fetSaving: Event when save a form editor.

    - fetComponentCreating: Event when create a component in form editor.

    - fetComponentCreated: Event after create a component in form editor.

    - fetComponentDestorying: Event when delete a component in form editor.

    - fetComponentRenamed: Event when renaming a component in form editor.

- Script Search Path: Specify the search path when compile Pascal script.

What's the Grammar of PascalScript?

PascalScript Grammar is almost the same with Object Pascal. But below are to be specified:

- Convertion from Integer to TObject, e.g. TObject(0) is not supported by PascalScript. You can use an alternative function to do it: function CnIntToObject(AInt: Integer): TObject;

- Default Parameter in function calling, and overload functions, are not supported by PascalScript.

- Interface Property is not supported by PascalScript. You can use the Get/Set method instead.

- Declaration of DLL functions is supported by PascalScript.

- Procedure Readln are implemented as an InputBox to recieve user input. Output of Procedure Writeln will be redirected to Script Window's Message Area.

How to use Libraries?

Functions or Procedures that can be called in CnWizards' PascalScript environment should be registered in CnWizards while compiling. Now CnWizards has registered some system functions including Sysutils, Classes, Windows and ToolsApi, etc. The registered list is in PSDecl directory in CnWizards installation destination. Note: The list Pascal files are not used in runtime in CnWizards, only for reference. They come from VCL source but only interface part left for registering and maybe modified for PascalScript grammar. Those functions or procedures listed in the PSDecl files can be called in PascalScript environment in CnWizards. For the details help of a function or procedure in the listed files, users can search Delphi's help for they're the same prototypes.

Some PascalScript Demos are placed in PSDemo directory in CnWizards installation destination. Users can read them.

Contents in both directory are in continuous development. Welcome to write customized PascalScript to enhance CnWizards and IDE.

How to Write Code?

You can use your favorite editor to write PascalScript code. Certainly, IDE's Code Editor is a good choice. You can write a script just like write Object Pascal code, and use the Code Input Helper of CnWizards to help your writing in IDE's Code Editor. Note: To use Code Input Helper or IDE's Code Insight, you need to add all needed path to your IDE Search Path. For example, if ToolsApi was used, "Source\ToolsAPI" directory need to be added. And if CnWizUtils.pas was used, "PSDeclEx" directory should also be added.

How to Play with Event?

A Pascal Script can be called manually or by event(s). You can use the global object "Event" to obtain the event type or parameters. Event is an instance of TCnScriptEvent. Its Mode property represents the event type, corresponding to smManual, smIDELoaded, smBeforeCompile, smAfterCompile, smFileNotify, smSourceEditorNotify, smFormEditorNotify. So we can know the event type if we check Event.Mode value in script. Some events contains not only the event type, but also some other information, e.g. filename, source editor, etc. In this situation, Event is an instance of TCnScriptEvent's sub class. We can use a typecast to convert Event to TCnScriptEvent's sub class to get more parameters.

More information, please refer to PSDeclEx\ScriptEvent.pas and other Event demos in PSDemo directory.

Links

Basic Operation

CnWizards Settings

About CnWizards

Copyrights 2001-2016 CnPack Team