Delphi: How to get (current code line, current unit, current function) without using Assertion?

冷暖自知 提交于 2019-12-04 07:55:54

You can bind your own TAssertErrorProc procedure to the AssertErrorProc variable. You might write something like this:

procedure OnAssert(const Message, Filename: string; LineNumber: Integer;
  ErrorAddr: Pointer);
begin
  ShowMessage(Format('Assert in file "%s" at line %d.', [Filename, LineNumber]));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  AssertErrorProc := OnAssert;
end;

The easiest way to map from the instruction pointer to unit name and line number is to use one of the various debugging libraries: madExcept, EurekaLog, JclDebug etc.

These tools all rely on the detailed map file that is produced by the linker. Although these libraries are best known for producing bug reports from unexpected exceptions, they have all the functionality that you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!