HelpNDoc's script debugging is typically done by emitting messages at generation time and (when needed) stopping execution intentionally at a precise point.

This page documents the four compiler-style directives you can use to output diagnostic messages:

{$HINT "This is a hint"}
{$WARNING "This is a warning"}
{$ERROR "This is an error"}
{$FATAL "This is a fatal error"}

…and the two location objects you can use to pinpoint where a problem originates at generation time:

Together, these let you:

Message directives

All four directives emit a message that appears in HelpNDoc's generation logs/output. They differ by severity and by whether they should be used to flag non-blocking diagnostics versus stop the process.

{$HINT "message"}

What it does
Emits an informational diagnostic message (a hint). This is best used for lightweight tracing.

Benefits

How to use it to debug

Example:

{$HINT "Entered BuildTopicNavigation"}

{$WARNING "message"}

What it does
Emits a warning message. This signals a potential problem, but typically does not justify stopping generation.

Benefits

How to use it to debug

Example:

{$WARNING "Topic has no short description; using title instead"}

{$ERROR "message"}

What it does
Emits an error message. Use this when something is wrong enough that output may be incorrect, or a required condition is not met.

Benefits

How to use it to debug

Example:

{$ERROR "Required variable 'ProductVersion' is empty"}

{$FATAL "message"}

What it does
Emits a fatal message indicating an unrecoverable condition. Use this when continuing would be pointless or dangerous (corrupt output, invalid state).

Benefits

How to use it to debug

Example:

{$FATAL "Unexpected state: NavigationRoot is nil"}

Practical rule of thumb:
HINT = trace, WARNING = suspicious but continue, ERROR = wrong and likely harmful, FATAL = cannot continue.

Run-Time Source Code Location Objects

HelpNDoc provides two run-time objects that describe where the script currently is (or where it was called from). These are especially useful when the same helper function is called from many places and you need to find which call site triggered a problem.

CurrentSourceCodeLocation

Represents the script location currently executing.

Properties:

Benefits:

Example (log current location):

print('--- Current location ---');
print('File: ' + CurrentSourceCodeLocation.File);
print('Name: ' + CurrentSourceCodeLocation.Name);
print('Line: ' + IntToStr(CurrentSourceCodeLocation.Line));

CallerSourceCodeLocation

Represents the script location of the caller that invoked the current routine.

Properties:

Benefits:

Example (log caller location):

print('--- Caller location ---');
print('File: ' + CallerSourceCodeLocation.File);
print('Name: ' + CallerSourceCodeLocation.Name);
print('Line: ' + IntToStr(CallerSourceCodeLocation.Line));

Practical Debugging Patterns

Pattern 1: Breadcrumb logging around suspicious code

Add prints before and after a block to see whether it is entered, and where execution stops.

print('Entering block at ' + CurrentSourceCodeLocation.File + ':' + IntToStr(CurrentSourceCodeLocation.Line));
// suspicious logic here
print('Leaving block at ' + CurrentSourceCodeLocation.File + ':' + IntToStr(CurrentSourceCodeLocation.Line));

Pattern 2: Reporting invalid input with call-site context

When a helper function receives unexpected data, log both current + caller locations so you know:

if SomeValue = '' then
begin
  print('ERROR: SomeValue is empty.');
  print('Detected at: ' + CurrentSourceCodeLocation.File + ':' + IntToStr(CurrentSourceCodeLocation.Line));
  print('Called from : ' + CallerSourceCodeLocation.File + ':' + IntToStr(CallerSourceCodeLocation.Line));
  exit;
end;

Choosing Between $ Directives and Run-Time Logging

Use {$HINT} / {$WARNING} when:

Use {$ERROR} / {$FATAL} when:

Use print + location properties when:

Summary