|
Language
Describes the DWS dialect of Object Pascal.
Featured IntroductionDWScript language is an Object Pascal dialect, it borrows most elements from Delphi, FreePascal and Prism/Oxygene, though with specificities of its own. For Pascal users, you'll find below a summary of difference so you can get started right way. Dialect SpecificitiesMemory ModelA garbage collector ensures that no script-objects or structures are leaked, however, you can invoke destructors explicitly. Attempts to access a destroyed object will fail with an exception and is "safe". Data TypesSee LanguageTypes for more details. DWScript base types are Integer, Float, Boolean and String. Classes, arrays (fixed-size and dynamic), records (with methods), enumerations, meta-classes, interfaces and delegates are supported too. Dynamic arrays support a set of pseudo-methods and operators (Add, Delete, IndexOf, Length, SetLength in...), and are true reference types. As of v2.2, sets, generics and closures are not yet supported. StatementsSee LanguageStatements for more details.
OperatorsSee LanguageOperators for more details.
Since pointers don't exist in the language, the and = operators are available for overloading. Code StructureSource code structure is essentially standard Pascal with the following specificities:
Variables are guaranteed to always be initialized. Variable declaration can feature an assignment, variable type can be inferred, for instance var i := 20; is equivalent to var i : Integer; i:=20; as well as var i : Integer := 20; Array constantsArray constants are delimited with square brackets [ ] and not parenthesis ( ). The syntax change was necessary to allow supporting inline static arrays definition, and make provisions for operators operating on arrays and future array comprehension extensions. const a1 : array [0..2] of String = ['zero', 'one', 'two']; var a2 : array [0..2] of String; a2 := ['zero', 'one', 'two']; Contracts ProgrammingContracts programming is supported with a syntax similar to the Oxygene language, procedures can have "require" and "ensure" sections, the "ensure" sections also support the "old" keyword. ConstructorsClassic constructor syntax is supported, but you can also specify a default constructor and use the "new" keyword to instantiate classes. Both lines of code below are equivalent: obj := TMyObject.Create(parameter); obj := new TMyObject(parameter); DelegatesFunction pointers are unified, there is no distinction between standalone function and method pointers. For instance the following code is valid: type TMyFunction = function (i : Integer) : String; var v : TMyFunction; v := IntToStr; v := someObject.SomeMethod; v := somInterface.SomeMethod; As long as the function or method prototype matches. You can use the '@' operator to explicit a function reference to remove ambiguity. | |