delphiarguments

How does WriteLn() really work?


Since the age of the dinosaurs, Turbo Pascal and nowadays Delphi have a Write() and WriteLn() procedure that quietly do some neat stuff.

Write('Hello':10,'World!':7); // alignment parameters

Now that I was typing this I've noticed that Write and WriteLn don't have the same brackets in the code completion dropdown. Therefore it looks like this was not automatically generated, but it was hard-coded by someone.

Anyway, am I able to write procedures like these myself, or is all of this some magic hardcoded compiler trickery?


Solution

  • Writeln is what we call a compiler "magic" function. If you look in System.pas, you won't find a Writeln that is declared anything like what you would expect. The compiler literally breaks it all down into individual calls to various special runtime library functions.

    In short, there is no way to implement your own version that does all the same things as the built-in writeln without modifying the compiler.