|
| |
This document describes the difference between Delphi Script and Object Pascal used in Delphi 5.
All variables in Delphi Script are always of Variant type. Typecasting is ignored.
Types in variables declaration are ignored and can be skipped, so these declarations are correct:
var a : integer;
var b : integerr;
var c, d;
Types of parameters in procedure/function declaration are ignored and can be skipped.
For example, this code is correct:
function sum(a, b) : integer;
begin
result := a + b;
end;
Type of array elements is ignored and can be skipped so these declarations are equal:
var x : array [1..2] of double;
var x : array [1..2];
These keywords are ignored:
interface, implementation, program, unit
You can use them but they have no effect.
"in" directive in uses is ignored
Delphi Script doesn't support type declarations. It tries to skip them but
complex declarations may cause parser to fail.
^ and @ operators are not supported.
You can't use the function name to set the return value, use Result to do so.
Nested routines are supported but you can't use variables of top level function from the nested one.
The following keywords are not supported:
as, asm, class, dispinterface, exports, finalization, inherited, initialization,
inline, interface, is, library, object, out, property, record, resourcestring, set, type
The following directives are not supported (note that some of them are obsolete and
aren't supported by Delphi too):
absolute, abstract, assembler, automated, cdecl, contains, default, dispid, dynamic, export, external,
far, implements, index, message, name, near, nodefault, overload, override, package, pascal, private
protected, public, published, read, readonly, register, reintroduce, requires, resident,
safecall, stdcall, stored, virtual, write, writeonly
These RTL functions aren't supported in Delphi Script:
Abort, Addr, Assert, Dec, FillChar, Finalize, Hi, High, Inc, Initialize, Lo, Low, New, Ptr, SetString, SizeOf, Str, UniqueString,
VarArrayRedim, VarArrayRef, VarCast, VarClear, VarCopy
Open array declaration is not supported.
CASE can be used for any types. So you can write
case UserName of
'Alex', 'John' : IsAdministrator := true;
'Peter' : IsAdministrator := false;
else
raise('Unknown user');
end;
Raise can be used without parameters to re-raise the last exception. You can also
use Raise with string parameter to raise the exception with the specified message string.
For example,
Raise(Format('Invalid value : %d', [Height]));
Threadvar keyword is treated as Var
[...] set constructors are not supported. You can use MkSet to create a set. For example,
Font.Style := MkSet(fsBold, fsItalic);
Set operator In is not supported. Use InSet to check whether a value is a
member of set. For example,
if InSet(fsBold, Font.Style) then
ShowMessage('Bold');
Note, that set operators '+', '-', '*', '<=', '>=' don't work correctly. You have
to use logical operators. For example,
ASet := BSet + CSet; should be changed to ASet := BSet or CSet;
CreateObject can be used to create objects that will be implicitly freed when no
longer used. So instead of
procedure proc;
var l;
begin
l := TList.Create;
try
// do something with l
finally
l.Free;
end;
end;
you can write
procedure proc;
var l;
begin
l := CreateObject(TList);
// do something with l
end;
Built in function Evaluate can be used to interpret string as program code
during runtime of a program and execute the code contained in the string. For example, you can write script like
Evaluate(ProcNames[ProcIndex]);
and the procedure which name is specified in ProcNames[ProcIndex] will be called.
Built in directive UseUnit can be used to dynamically add to uses section any unit at runtime.
For example, the following script
if FileExists('Update.pas') then
begin
UseUnit('Update.pas');
Evaluate('Update.DoUpdate');
end;
checks whether the unit named Update.pas exists and if so calls DoUpdate method from there.
UnloadUnit directive unloads any unit added by "uses" section or with UseUnit call.
|
|
|
Other
Products
|
|

|
|