![]() |
![]() |
![]() |
DelpWebScriptDWS Basics |
|
![]() |
Homepage DWS ![]() |
First StepTo use DelphiWebScript in your Delphi project follow these steps:
Writing Script ProgramsDWS programs use almost the same syntax as Delphi programs. The most important difference is that there is no need for variable declaration: a := 2; You can use IF statements and FOR, WHILE and REPEAT-UNTIL loops as known from Delphi: if true then send (1) else send (2); Of course it's also possible to create blocks of statement's using BEGIN-END: for x := 0 to 10 do Variables and DatatypesIf you like to use a variable - e. g. x - in your script the only thing you have to do is to assign a value to x: x := 1; The first value you assign to a variable determines the type. The assignment in the expample creates a variable x of type integer with value 1. Possible datatypes are integer, float, string and boolean: x := 1; // integer If you use uninitialized variables in your script the compiler shows an error message: if x = 0 then send (y); The compile doesn't know anything about the types of x and y. The compiler also shows an error message if you try to assign incompatible values to a variable: a := 2; To create a variable of type float you have to use the point - notation even if it's not necassary: f := 0.0; ConstantsIt's also possible to declare constants in a DWS program. Unlike Delphi it's possible to declare constants everywhere in a script program, even in a loop: const h = 'hello'; Include FilesIt's also possible to include script code located in an external file. To include a external file use this syntax: {$I 'filename'} If you don't use a file extension DWS adds ".dws". In difference to delphi you always have to put the filename in quotes. DWS looks for the include file in the path: TDelphiWebScript.IncludePath. |