Hello everyone,
I wanted to share my view on multi-line strings.
It's not a particularly original idea, but it's inspired by various ‘Pascal server pages’ such as:
https://www.yanniel.info/2011/12/pascal-server-pages-script.htmlExplanatory code follows:
program test01;
const LE = #10;
var s1, s2, s3: string;
d: TDate;
begin
d:= encodedate(2025, 07, 28);
s1 := {$MULTILINESTRING_RAW_BEGIN} // all ignored until EOL, auto-idented by 8
SELECT o.*, C.Company{$PAS:LE}
from Orders O{$PAS:LE}
join Customer C{$PAS}LineEnding{$RAW}
on o.CustNo=C.ID{$PAS:LE}
where{$PAS}LE{$RAW}
O.saledate like '{$PAS}FormatDateTime('yyyy', [d]){$RAW}%';
{$MULTILINESTRING_RAW_END}
Writeln(s1);
// MULTILINESTRING_OS_BEGIN means:
// same as MULTILINESTRING_RAW_BEGIN but all EOL are replaced by LineEndig
s2 := {$MULTILINESTRING_OS_BEGIN} // all ignored until EOL, auto-idented by 8
SELECT o.*, C.Company
from Orders O
join Customer C
on o.CustNo=C.ID
where
O.saledate like '{$PAS}FormatDateTime('yyyy', [d]){$RAW}%';
{$MULTILINESTRING_OS_END}
Writeln(s2);
// MULTILINESTRING_SQL_BEGIN means:
// same as MULTILINESTRING_RAW_BEGIN but all EOL are replaced by space (#32)
s3 := {$MULTILINESTRING_SQL_BEGIN} // all ignored until EOL, auto-idented by 8
SELECT o.*, C.Company
from Orders O
join Customer C{$PAS} /* need spaces before EOL? -> */ {$RAW}
on o.CustNo=C.ID
where
O.saledate like '{$PAS}FormatDateTime('yyyy', [d]){$RAW}%';
{$MULTILINESTRING_SQL_END}
Writeln(s3);
end;
What do you think?
Thanks
nomorelogic
Edit:
correction in code
Edit 2:
Here is a brief explanation:
The directive {$MULTILINESTRING_OS_BEGIN} is equivalent to a single apostrophe but activates a multiline string
The directive {$PAS:LE} consists of two tokens:
- ‘{$PAS:’ activates Pascal mode, while ‘}’ closes Pascal mode and returns to multiline string mode; in this case, it writes the constant LE to the string
The directives {$PAS} and {$RAW}, respectively:
- activates Pascal mode
- activates raw mode (back to multiline string)
The directive {$MULTILINESTRING_RAW_END} closes multi-line string mode