将对象类名作为参数

发布于 2024-12-06 00:16:22 字数 344 浏览 0 评论 0原文

我有一个 TC 脚本,可以处理各种屏幕的报告选项。窗口类名称在每个屏幕上都会发生变化,并且由于我希望该脚本在翻译环境中工作,因此窗口标题也会发生变化。第一部分工作正常,但如何解释窗口名称的变化?如果我删除标题,TC 就会出现不明确的窗口识别错误。

当前代码片段(带有一个屏幕的标题):

w := p.WaitWindow('*', 'Options', 1, 10000);   
if w.Name='frmBasicOpt' then
begin
....

我可以将类名设置为输入的参数,以便我可以省略标题吗?如果是这样,我该怎么做?

头……疼。

谢谢!

I have a TC script that handles report options for a variety of screens. The window class name changes on each screen and, as I want this script to work in a translated environment, the window caption will be changing as well. The first part works correctly but how to I account for the changing window name as well? If I remove the caption, TC bombs with an ambiguous window recognition error.

Current code snippet (with the caption of one screen) :

w := p.WaitWindow('*', 'Options', 1, 10000);   
if w.Name='frmBasicOpt' then
begin
....

Can I set the class name as a parameter that is fed in so I can leave out the caption? If so, how can I do this?

Head... hurt.

Thanks!

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

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

发布评论

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

评论(1

寂寞美少年 2024-12-13 00:16:22

不确定我是否理解这项任务,但我会尽力在我理解的范围内提供帮助。
因此,窗口类名称是动态的,这就是您用通配符屏蔽它的原因。但你告诉你,如果你能够参数化它,你无论如何都想使用类名。所以,似乎有一种方法可以在测试执行期间从某处获取类名。如果是这样,您可以将类名放入一个变量,并将该变量作为参数传递给 WaitWindow 方法,并屏蔽标题以避免使用特定于语言的标题:

clsName := ....; // get it from somewhere
w := p.WaitWindow(clsName, '*', 1, 10000);
if w.Name='frmBasicOpt' then
begin

如果我的理解不正确,则无法知道如果事先指定了类名,您可以考虑使用不同的方法来识别选项窗口而不指定标题。可能的解决方案包括:

  1. 当对话框打开时,它会变为活动状态。因此,您可以通过 Sys.Desktop.ActiveWindow 获取该对话框。

  2. 如果这是一个 MFC 应用程序,请注意窗口的 ControlID 属性 - 它可以在应用程序的代码中设置,用于对象识别。因此,您可以使用 FindChild 方法通过属性值查找窗口。

  3. 如果窗口有一些仅特定于该窗口的子对象,您可以创建一个函数来获取 Process 对象的所有子窗口 (FindAllChildren),迭代列表并检查其中哪个具有这些特定的子窗口对象。

这对你有用吗?如果没有,那么有关您的任务的更多信息可能会帮助我提出其他建议。

亚历克斯

Not sure I understand the task, but I will try to help to the extent of my understanding.
So, the window class name is a dynamic thing, that's why you masked it with a wildcard. But you tell that you want to use the class name anyway if you are able to parameterize it. So, it seems like there is a way to get the class name during test execution from somewhere. If so, you can put the class name to a variable, and pass this variable to the WaitWindow method as a parameter, and mask the caption to avoid using language-specific captions:

clsName := ....; // get it from somewhere
w := p.WaitWindow(clsName, '*', 1, 10000);
if w.Name='frmBasicOpt' then
begin

If my understanding is not correct and there is no way to know the class name beforehand, you may consider using a different approach to identify the Options window without specifying the caption. The possible solution include:

  1. When the dialog opens, it becomes active. So, you can get the dialog through Sys.Desktop.ActiveWindow.

  2. If this is an MFC application, pay attention to the ControlID property of the window - it's something that can be set in the application's code, to be used for object recognition. So, you can use the FindChild method to find the window by the property value.

  3. If the window has some child objects that are specific only to this window, you can create a function that will get all child windows of the Process object (FindAllChildren), iterate through the list and check which of them has those specific child objects.

Does anything for this work for you? If not, then a little bit more information about your task could probably help me make other suggestions.

Alex

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