This section introduces the fundamental elements of the HelpNDoc scripting language. Understanding these basics will help you write and modify scripts to automate tasks in HelpNDoc, or create templates to control the documentation's output. This guide covers variables, operators, control structures, and comments, which form the building blocks of your scripts.

Variables

Declaration and Types

Variables are used to store data that your script can manipulate. In HelpNDoc's scripting language, you need to declare variables with a specific type before using them.

Common Data Types

See: Base types 

Example

var Age: Integer;
var Name: String;
var Price: Float;
var IsComplete: Boolean;
var EventDate: TDateTime;
var Scores: array[0..2] of Integer;
begin
  Age := 25;
  Name := 'Alice';
  Price := 99.99;
  IsComplete := True;
  EventDate := Now();
  
  Scores[0] := 85;
  Scores[1] := 90;
  Scores[2] := 95;

  Print('Name: ' + Name);
  Print('Age: ' + Age.ToString);
  Print('Price: ' + Price.ToString);
  Print('Is Complete: ' + IsComplete.ToString);
  Print('Event Date: ' + DateTimeToStr(EventDate));
  Print('Scores: ' + Scores[0].ToString + ', ' + Scores[1].ToString + ', ' + Scores[2].ToString);
end;

Operators

Operators are symbols that tell the script to perform specific mathematical, logical, or comparison operations.

Assignment Operator

Arithmetic Operators

Comparison Operators

Logical Operators

Example

var
  Sum, Difference: Integer;
var
  IsValid: Boolean;
begin
  Sum := 10 + 5;
  Difference := 15 - 7;
  IsValid := (Sum > Difference) and (Difference > 0);
end;

Control Structures

Control structures allow you to control the flow of your script based on conditions or repetitive tasks.

If Statements

Use if statements to execute code only if a specific condition is true.

Syntax:

if Condition then
begin
  // Code to execute if the condition is true
end
else
begin
  // Code to execute if the condition is false
end;

Example:

var
  Age: Integer;
begin
  Age := 25;
  if Age >= 18 then
    Print('You are an adult.')
  else
    Print('You are not an adult.');
end;

For Loops

Use for loops to repeat a block of code a specific number of times.

Syntax:

for Variable := StartValue to EndValue do
begin
  // Code to repeat
end;

Example:

var
  i: Integer;
begin
  for i := 1 to 5 do
  begin
    Print('Iteration: ' + i.ToString);
  end;
end;

While Loops

Use while loops to repeat a block of code as long as a condition is true.

Syntax:

while Condition do
begin
  // Code to repeat
end;

Example:

var
  Counter: Integer;
begin
  Counter := 0;
  while Counter < 5 do
  begin
    Print('Counter: ' + Counter.ToString);
    Inc(Counter); // Increment the counter
  end;
end;

Comments

Comments are used to add explanations or notes in your code. They are ignored by the script during execution.

Single-line Comments

Use // for single-line comments.

Example:

// This is a single-line comment
var
  Age: Integer;
begin
  Age := 30; // Setting the age
end;

Multi-line Comments

Use { } or (* *) for multi-line comments.

Example:

{
  This is a multi-line comment
  that spans multiple lines.
}
var
  Name: String;
begin
  Name := 'HelpNDoc User';
end;