There are compiler directives {$INCLUDE %FILE%} and {$INCLUDE %LINE%}
They DON'T load files. Instead they insert [current file name] / [current line] at compile time. So you can make something like this:
DebugLn ('Error in file ' + {$INCLUDE %FILE%} + ' on line ' + {$INCLUDE %LINE%});
I wanted to make this shorter, to avoid repeating the same long string everywhere in the code. So I wrote a macro like this:
{$MACROS ON}
{$DEFINE ErrorInfo:='Error in file ' + {$INCLUDE %FILE%} + ' on line ' + {$INCLUDE %LINE%}}
DebugLn (ErrorInfo); // this should write the current file and line number
But this doesn't work. The problem is that $INCLUDE executes first so it inserts a fixed file name / line number during the macro declaration. Wherever this macro is used, always the same (incorrect) data is displayed. Not the current line, but line where macro was first declared.
If anyone has experience with FPC macros I'd like to know if there's a way around this?