DWScript is a versatile language that can run in different environments. Understanding the operating mode is crucial as it affects available features and libraries.
In this mode, DWScript runs directly on the host machine (Windows) via the CLI or an embedded host application.
This is the mode used to serve this website. DWScript files (.dws) are executed by the web server to generate dynamic HTML content.
WebRequest and WebResponse object.Print and PrintLn functions write directly to the HTTP response stream.DWScript can be compiled into JavaScript to run in a web browser or Node.js environment. This allows you to write the frontend code in the same language as your backend.
asm blocks containing raw JavaScript.Integer behaves like a JS number (53-bit precision safe).Beyond the execution environment, DWScript supports two primary ways of structuring source code: Script Mode and Unit Mode.
This is the most flexible mode, where you can mix variables, types, and procedures directly with executable code. It is ideal for small tasks and web server pages.
var or type anywhere before its first use.PrintLn calls between type and procedure definitions.PrintLn('Starting script');
type TUser = record Name: String; end;
var u: TUser;
u.Name := 'Alice';
procedure SayHello;
begin
PrintLn('Hello ' + u.Name);
end;
SayHello; Starting script Hello Alice
This mode follows the classic Object Pascal structure and is used for building reusable modules or larger applications. It enforces a strict separation between declarations and implementation.
unit or program.interface and implementation blocks.type keyword).unit MyUtils;
interface
type
TPoint = record
X, Y: Integer;
end;
implementation
// Code logic goes here...
end. Web server .dws files always start in Script Mode. If you want to use Units, you create separate .pas files and include them via uses.