|
 ObjectScript (cScript) Tips and Scripts

Topics
How do I return a value from an ObjectScript function?
My script's DLL crashes the IDE when
the IDE closes.
Replacement for EDITSIZE.SPP Script (demonstrates
calling a DLL from a script)
Quickie Method to Attatch a Script to a Keystroke
BC5 Sound Scheme Script
Autosave Editor Files Prior to Debugger Running
String Functions Appear to be Missing
Removing Messages from the Message Window Before
a Debug Session.
Syntax Highlighting for Scripts
Running Your Own Scripts on IDE Startup
Script to Check WINHELP.INI for Errors

How do I return a value from an
ObjectScript function?
If you try the C-style function declaration you will get an error since
you can't define the return type of a function in cScript. Instead, all
you have to do is return a value without declaring the return type:
GetValue()
{
if (integer) return 1;
if (string) return "Text";
}
Note that the function can return any data type.

My script's DLL crashes
the IDE when the IDE closes.
Be sure to turn on the Multithread option for your DLLs project in
TargetExpert. DLLs you write to call from scripts must use the same RTL as
the IDE which uses the mulit-threaded version of the RTL.

Replacement for EDITSIZE.SPP Script
I wrote this script to demonstrate calling a user-written DLL from
a script. This script calls a function in a DLL which enumerates the child
editor windows and places the new window down and to the right of the right-most
existing editor window. Now your new editor windows can be the size you
desire and they won't all be created on top of one another. Another advantage
to this script is that you now set the editor window width and height in
pixels so you know exactly how large the window will be.
The zip file includes the script file, the DLL source
code, a project file for the DLL, the pre-built DLL, and a README.TXT file.
Download now (17K). Note: The DLL in
the zip file was built with BC++ 5.01. If you encounter errors then
rebuild the DLL using the project provided.

Quickie Method to Attatch
a Script to a Keystroke
Installing keyboard commands is a bit confusing so here is a technique
to use an existing keyboard command for adding in a temporary script. What
I did (Ian) was hook into the bookmark code:
import editor;
onn editor:>GotoBookMark(num)
{
if (num == 1) DoCustomFunction();
else pass(num);
}
DoCustomFunction()
{
// get reference to current position
declare ep = editor.TopView.Position;
// ref. a block to use for editing
declare eb = editor.TopView.Block;
// do some processing based on the
above useful objects
}
This subclasses the editor and DoCustomFunction() will
then be called any time the bookmark 1 is used (in standard keyboard Ctrl-1).
You can simply then run the script file from the IDE to quickly set up
a new command.

BC5 Sound Scheme Script
Associate wave files with IDE events. Comes with sample wave files.
Fully configurable to add your own wave files via an easy-to-use dialog
box. Give it a try! Download now (317K). (This
was put together rather hastily so let me know (Kent) if you encounter
any problems.)

Script to Create a Shell Header
File
This script will create a ready-to-go header file for you with the
sentry (#ifndef __HEADER_H, etc.) and the "#ifdef __cplusplus
" defines already added. Add the script to your startup scripts. Then
use Ctrl-KZ to generate a header. Click here to download
(2K).

Autosave Editor Files Prior
to Debugger Running
The Autosave feature is not functional for editor files. If you want
your editor files to be saved just before you run the debugger then use
the following script:
import IDE;
import debugger;
on debugger:>DebugeeAboutToRun() {
IDE.FileSaveAll();
pass();
}

String functions appear
to be missing.
If you have been trying to work out why you can't call String functions
on a string variable, it is because there are two sorts of text, string
is the built-in type, roughly equivalent to a char array, whereas String
is a class object--note the initial capitalization. To perform operations
such as String::Index you need to make a String variable:
strVar = "I've Got A Little
Black Book With My Poems In";
index = strVar.Index("Book"); //
Runtime failure undefined method
StrVar = new String(strVar);
index = strVar.Index("Book"); //
returns 25 (give or take)

Removing messages from the
message window before a debug session.
If you are like me you may not like the volume of messages that build
up in the Runtime and Buildtime tabs of the Message window. You can use
the following script to automatically delete the messages prior to the
debugger running. Place this script in a new text file and save it with
the name "clearmsgs.spp". Then choose "Run File" from
the speed menu to run the script.
print ("clearmsgs.spp");
import IDE;
import debugger;
on debugger:>DebugeeCreated() {
IDE.ViewMessage("Runtime");
// switch to the Runtime tab
IDE.KeyboardManager.SendKeys("^a");
// send Ctrl-A
pass();
}
on debugger:>DebugeeAboutToRun() {
// optional
IDE.ViewMessage("Buildtime");
// switch to the Buildtime tab
IDE.KeyboardManager.SendKeys("^a");
// Ctrl-A again
pass();
}

Syntax Highlighting for Scripts
This script was written by Klaus Krull at Borland. It will provide
syntax highlighting for ObjectScript (.spp) files. It includes a token
file and a script as well as a HIGHLITE.TXT file to explain where to place
the files. Download now.

Running your own scripts on
IDE startup.
As time goes on you will probably have several of your own scripts
(or scripts borrowed from others) that you want to run when the IDE loads.
A convenient approach is to have a script file called "myscripts.spp"
that loads all of your scripts. Place this file in a directory called "scripts"
or any other location, but not in the \bc5\scripts directory (you don't
want to lose your scripts when you upgrade compiler versions). You can
then add the name of this file to your startup scripts (Options | Environment
| Scripting) and then append the script path to point to your "scripts" directory.
The "myscripts.spp" file might look something like this:
print("myscript.spp");
print("Loading My Scripts");
import scriptEngine;
if (!scriptEngine.IsLoaded("msgnotop.spp"))
scriptEngine.Load("msgnotop.spp");
if (!scriptEngine.IsLoaded("evaltips.spp"))
scriptEngine.Load("evaltips.spp");

Script to check WINHELP.INI for
errors.
If you get a blank message box when requesting help, run this script.
(Paste it into a new file, save as checkhelp.spp and then Script | Run
File from the edit window). The results are shown in the script window.
Edit your WinHelp.ini by hand, commenting out any line in error.
import IDE;
DoHelpCheck()
{
print "Checking help...";
declare errors = 0;
declare winHelpIni = "c:\\windows";
winHelpIni = IDE.DirectoryDialog
("Select Windows directory",winHelpIni,winHelpIni);
winHelpIni += "\\winhelp.ini";
if (!FindFirstFile(winHelpIni)) {
print "Help ini
file", winHelpIni, "is missing";
return;
}
declare ed = new EditBuffer(winHelpIni, true,
true);
declare pos = ed.Position;
declare block = ed.Block;
for (declare i = 1; i <= pos.LastRow; i++)
{
pos.Move(i,1);
block.Begin();
pos.MoveEOL();
block.End();
declare iniLine = new String(block.Text);
if (iniLine.SubString(0,1).Text
!= ";") { //
Check comment
declare eq = iniLine.Index("=");
// Ignore header line
if (eq) {
declare path = iniLine.SubString(eq);
declare fileName
=
path.Text +
"\\" + iniLine.SubString(0,eq
- 1).Text;
if (!FindFirstFile(fileName))
{
print
"Help file", fileName, "is
missing";
errors ++;
}
}
}
}
ed.Destroy();
print pos.LastRow, "lines
checked,", errors, "errors found.";
}
// Run directly when script
loaded
DoHelpCheck();

BC++ 5.0 FAQ Page | BC++ 5.0
Tips Page
|