Better load them from resources, easier to post compilation translate them
How would you do that actually?
Lots of ways, for example:
- use a resourcestring section, though that posses the same problem with multi-line strings as any other code;
- go down to basics and write your strings in an rc script as a string table, reading them back with a TStringTableResource, which has the advantage than some (most?) resource compilers allow you to use C-like scapes in the rc script;
- ... etc ...
What we actually do is to use string concatenation with C-like scapes, e.g.
const {or resourcestring}
sBanner = 'I Made It! First Ever Algorithm\n' +
'Copyright 1842 by Ada A. Lovelace';
which we then pass through an "unscape' function when in use. But I realize this is just a crutch; it would be nicer if the compiler allowed us to, at least, use another operator meaning "add a line end before concat", if not a special "multiline string" construct. Say. something like (just an example!):
const {or resourcestring}
sBanner = 'I Made It! First Ever Algorithm' *
'Copyright 1842 by Ada A. Lovelace';
instead of:
const {or resourcestring}
sBanner = 'I Made It! First Ever Algorithm' + LineEnding +
'Copyright 1842 by Ada A. Lovelace';
And, yeah, let's not kid ourselves: the main drive for this feature is to save typing
but it also helps to prevent some annoying bugs, like forgetting one (or more!) of those " + LineEnding +" or adding one where it's not wanted when you're adding a "wall-of-text" constant like, say, a console program "help". Of course, one could (like I do sometimes) just write that wall of text in its own text file and pass it through a "pascalifier", but again: less typing? lazy programmers? don't make the tool chain too long or you'll tangle in it?
Ok, I'm running out of ink; I'll stop here ("wall of text", indeed!)
Oh! Just one thing:
But there is already a solution to that that works perfectly fine in current fpc:
{$Macro on}
{$Define ln:=+ LineEnding}
const
mls = 'multi'ln +
'line'ln +
'string';
[... etc ...]
A hint, if I may: better shut off macros or undefine "ln" when it's no longer needed; otherwise you might find all your
WriteLn()'s converted to "
Write+LineEnding()"
ETA: In case somone takes it seriously: The compiler won't really do that; it was just to illustrate one drawback of using macros
a la brava.