起源:
用习惯了c#之Exception的StackTrace,在程序出异常crash时候能够以其定位出问题的模块及行号,用回Delphi 2009,发现没有这东西。
显然,在编译环境日新月异的今天,是不科学的。分析Delphi的Exception,发现些线索:StackTrace。
应该有戏!
继续下去,验证输出这个StackTrace,它是空的,里面没有预想要的内容。再深究去,发现并没想象那么容易,它扯到不少蛋。
1、Exception类
Delphi 2009中,StackTrace是如此定义的,与它一起的还有几个var:
Exception = class(TObject) private ... protected ... public ... property StackTrace: string read GetStackTrace; property StackInfo: Pointer read FStackInfo; { $IFDEF MSWINDOWS} class var // Hook this function to return an opaque data structure that contains stack information // for the given exception information record. This function will be called when the // exception is about to be raised or if this is an external exception such as an // Access Violation, called soon after the object is created. GetExceptionStackInfoProc: function (P: PExceptionRecord): Pointer; // This function is called to return a string representation of the above opaque //<