如何在运行时获取接口的名称?

发布于 2024-07-29 18:06:23 字数 108 浏览 1 评论 0原文

如果我有一个实现接口的对象,那么使用 RTTI 查找接口并获取其 GUID 并不是太困难。 但如果我想要它的名字,有什么办法可以得到它吗? 获取类的名称很简单,但对于接口来说似乎有点棘手......

If I have an object that implements an interface, it's not too difficult to use RTTI to look up the interface and obtain its GUID. But if I want its name, is there any way to get that? It's simple enough to get a class's name, but for interfaces it seems a bit trickier...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧桑㈠ 2024-08-05 18:06:23

棘手的部分是从接口获取 RTTI。 如果您成功做到了这一点,那么 PTypeInfo 记录指针中应该已包含该名称。

在我的一个程序中,我编写了一个特殊的注册系统,将 GUID 映射到字符串,以便我可以报告对 QueryInterface 的失败调用和失败的“as”转换。 那是在 delphi 2005 中。我的理解是,在后来的 Delphi 版本中,接口的 RTTI 已经取得了进步,因此我可能不再需要该系统了。

The tricky part is getting RTTI from an interface. If you've managed to do that, then you should already have the name there in the PTypeInfo record pointer.

In one of my programs, I wrote a special registration system that mapped GUIDs to strings so that I could report failed calls to QueryInterface and failed "as" casts. That was in delphi 2005. My understanding is that in later Delphi versions RTTI for interfaces has progressed such that I might not need that system anymore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文