Rol*_*son 4 delphi function-pointers delphi-2007
我有一个指向这样的函数的指针.
TTestEvent = function(): Boolean;
procedure ExecuteTest(aTest: TTestEvent; aType: String);
begin
if aTest then
NotifyLog(aType + ' success')
else
TestError(aType + ' failed');
end;
// Call the test
procedure TestAll;
begin
ExecuteTest(LoadParcels, 'LoadParcel');
end;
Run Code Online (Sandbox Code Playgroud)
但是从functionpointer aTest中提取函数的名称会更好.
而不是
aType + ' success'
Run Code Online (Sandbox Code Playgroud)
我想要类似的东西
ExtractName(aTest) + ' success'
Run Code Online (Sandbox Code Playgroud)
这可以在Delphi 2007中完成吗?
如果您使用我们的一些开源类,您将能够找到任何符号的名称.
.map通过在项目选项中设置"详细地图",您必须在构建可执行文件时创建文件.
然后,您可以.map使用.exe,或压缩.map到我们的专有.mab格式,可以附加到.exe.该.mab格式仅仅是一个很多比更高效的.zip 完成这个任务或其他:它比原来的小10倍左右.map的文件(即比JCLDebug或MaxExpect报价小得多,而且比使用标准的"远程调试符号"非常小嵌入项目选项).
然后,您可以使用TSynMapFile该类从.map文件中检索调试信息,或嵌入到以下内容中的信息.exe:
function ExtractName(aSymbolAddress: pointer): string;
var i: integer;
begin
with TSynMapFile.Create do // no name supplied -> will read from .exe
try
i := FindSymbol(aSymbolAddress);
if i>=0 then
result := Symbols[i].Name else
result := '';
finally
Free;
end;
end;
Run Code Online (Sandbox Code Playgroud)
它适用于函数名称,也适用于任何其他符号,如方法或全局变量.
请参阅有关该课程的博客文章.请注意,即使我们的mORMot框架或其日志记录功能使用它,您也不需要使用整个框架(只是SynCommons.pas和SynLZ.pas单位).请参阅"SQLite3\Samples\11 - 异常日志记录"子文件夹中的Map2Mab.dpr程序,将.map文件内容嵌入到.exe中.