如何检查接口属性的可见性?

发布于 2024-09-29 00:09:32 字数 229 浏览 0 评论 0原文

我已经开始在 Delphi 2010 中编写 Web 服务,并进行单元测试以确保它们按计划运行。我的代码单元测试通过了,但一个 Web 服务方法在作为服务调用时(即通过 SoapUI)没有返回值。经过几个小时的代码搜索后,我发现这是因为我的返回对象的属性不在界面的已发布部分中;他们在公共区域。

有没有办法让我的单元测试检查对象的变量可见性,以便我将来可以避免这个问题?我试图找到一种使用 RTTI 的方法,但没有找到任何东西。

I have started writing web services in Delphi 2010 and am unit testing to make sure they function as planned. My unit tests of the code passed but one web service method didn’t return a value when called as a service (i.e. through SoapUI). After many hours of searching through the code I discovered it was because the properties on my return object weren’t in the published section of the interface; they were in the public section.

Is there a way for my unit tests to check variable visibility on objects so I can avoid this problem in the future? I was trying to find a way with RTTI but haven’t been able to find anything.

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

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

发布评论

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

评论(2

俏︾媚 2024-10-06 00:09:32

您可以通过尝试访问某个属性的 RTTI 来确定该属性是否已声明为已发布。公共财产没有 RTTI,而发布的财产则有。

类似这样的内容:

if (GetPropInfo(myobject, "PropertyName") != null) then 
    // it's published...

有关 RTTI 的更多信息,请参阅 Brian Long 的文章:http:// www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm

You can determine whether a property was declared published by attempting to access that property's RTTI. A public property has no RTTI, a published property does.

Something like this:

if (GetPropInfo(myobject, "PropertyName") != null) then 
    // it's published...

For more info on RTTI, see Brian Long's article: http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm

淡笑忘祈一世凡恋 2024-10-06 00:09:32

您可以使用 RTTI 轻松完成此操作。您可以在 TypInfo 单元中使用经典的 RTTI 函数 GetPropInfo。如果它返回nil,则不存在该名称的已发布属性。或者您可以使用扩展 RTTI 查找它并检查可见性属性,这将告诉您它声明的可见性级别。

You can do it with RTTI easily enough. You can use the classic RTTI function GetPropInfo in the TypInfo unit. If it returns nil, then no published property by that name exists. Or you can look it up with extended RTTI and check the Visibility property, which will tell you what visibility level it's declared at.

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