使用delphi枚举单元的全局方法
假设我有一个像这样的单元
unit sample;
interface
function Test1:Integer;
procedure Test2;
implementation
function Test1:Integer;
begin
result:=0;
end;
procedure Test2;
begin
end;
end.
是否可以在运行时枚举单元sample
的所有过程和函数?
suppose i have a unit like this
unit sample;
interface
function Test1:Integer;
procedure Test2;
implementation
function Test1:Integer;
begin
result:=0;
end;
procedure Test2;
begin
end;
end.
Is possible enumerate all the procedures and functions of the unit sample
in runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不会。RTTI 不是为独立方法生成的。希望这将在以后的版本中得到修复(他们可能需要 TRttiUnit 类型来做到这一点),但目前它不可用。
No. RTTI is not generated for standalone methods. Hopefully this will be fixed in a later version, (they'd probably need a TRttiUnit type to do that,) but for now it's not available.
您可以使用 JCL 和他们伟大的 JclDebug.pas。
试试这个:
You could extract that information from some kind of debug info (TD32, Map file, Jdbg, etc.) using JCL and their great JclDebug.pas.
Try this:
我不这么认为。
这是一个编译时配置,使用它是为了让编译器知道哪个函数名称正在被调用或没有被调用。据我所知,在运行时没有什么比列出这些函数更接近的了。
Delphi 优秀的运行时特性来自 RTTI,您可能想看看它提供了与此相关的功能。但正如我所说,我认为这是不可能的(要知道我已经研究 RTTI 相当长一段时间了......)。
编辑:哦,顺便说一句,编译后,函数会丢失其人类可读的名称(地址)。有一些表可以将这些名称精确定位到地址,最值得注意的是 RTTI 和调试信息。
I don't think so.
That is a compile-time config, it's used so as the compiler knows which function name is being called or not. As far as I know, there is nothing at runtime which comes close to listing these functions.
Delphi's excellent runtime features come from RTTI, you might want to see what it offers in relation to this. But as I said, I don't think it's possible (know that I've delved in RTTI for quite some time...).
Edit: Oh and by the way, after compilation, functions lose their human-readable names (to addresses). There are some tables which pinpoint those names to addresses, most notably, RTTI and the Debug info.