Getting the current line number in Delphi

Note to self: There is an easy way to get the current line number in Delphi, using the following function and JclDebug:

function GetCurrentLineNumber: Integer;
  ModInfo: TJclLocationInfo;
  ModInfo := GetLocationInfo(ReturnAddress);
  Result := ModInfo.LineNumber;

ReturnAddress is a compiler magic function in the system unit, introduced with Delphi XE2. TJclLocationInfo and GetLocationInfo are from JclDebug.

Use it like this:


Edit: JclDebug already contains a function LineByLevel which does the same as my function above and more. There are other useful functions there, like TraceLog.