【问题标题】:How to target a child widget that is contained within multiple parent widgets in order to change the properties?如何定位包含在多个父小部件中的子小部件以更改属性?
【发布时间】:2020-11-25 11:25:43
【问题描述】:

客户端需要应用程序将颜色插入到特定实例的应用程序中,因此只有在必要时才会用颜色填充字段,我正在使用右键单击上下文菜单来执行此操作。

我创建了一个示例应用程序,它使用此代码并从 JSON 文件中提取小部件名称。

DEFINE VARIABLE hHandle AS HANDLE NO-UNDO.
DEFINE VARIABLE widgetName AS CHARACTER NO-UNDO.
DEFINE VARIABLE colourNumber AS INTEGER NO-UNDO.

FOR EACH Results-WidgetList:
    ASSIGN
        widgetName = Results-WidgetList.tt-widName /* these assignments are just getting the info */
        colourNumber = INT(Results-WidgetList.tt-colour)
        .
    hHandle = SESSION:FIRST-CHILD.
    DO WHILE VALID-HANDLE(hHandle):
        IF hHandle:TYPE = "FIELD-GROUP" THEN LEAVE.
        hHandle = hHandle:FIRST-CHILD.
    END.

    hHandle = hHandle:FIRST-CHILD.
    DO WHILE VALID-HANDLE(hHandle):
        IF hHandle:TYPE = "FILL-IN" AND hHandle:NAME = widgetName THEN LEAVE.
        hHandle = hHandle:NEXT-SIBLING.
    END.

    ASSIGN
        hHandle:BGCOLOR = colourNumber.

END.
       

这在我的示例应用程序中工作得非常好,但是一旦我尝试在主应用程序中实现它,它就看不到特定的小部件,因为它正在循环通过最顶层的父容器并且没有进一步。

有没有办法获取其中包含的元素?

【问题讨论】:

    标签: openedge progress-4gl


    【解决方案1】:

    我不确定您为什么要从 JSON 文件加载内容而您没有显示,所以我无法对此发表评论。但是,一般来说,您需要“遍历小部件树”。以下 sn-p 可能会有所帮助:

    /* walk the widget tree so that we can update the dcolor for the named field
     */
            
    procedure tweakTree:
                     
      define input parameter w     as handle    no-undo.
      define input parameter wName as character no-undo.
      define input parameter dClr  as integer   no-undo.
      
      define variable n as handle no-undo.
    
      n = w:first-child no-error.
      if valid-handle( n ) then
        run tweakTree( n, wName, dClr ).
      
      n = w:next-sibling no-error.
      if valid-handle( n ) then
        run tweakTree( n, wName, dClr ).
       
      if w:type = "fill-in" and w:name = wName then
        do:
          if session:window-system = "tty" then
            w:dcolor  = dClr.
           else
            w:fgcolor = dClr.
        end.
                
      return.
      
    end.  
        
    define variable c1 as character no-undo.
    define variable c2 as character no-undo.
    
    form c1 with frame f1.
    form c2 with frame f2.
    
    assign
      c1 = "abc"
      c2 = "123"
    .
    
    display c1 with frame f1.
    display c2 with frame f2.
    
    pause.
    
    run tweakTree( current-window, "c1", 2 ).
    run tweaktree( current-window, "c2", 1 ).
    
    pause.
    

    【讨论】:

    • 感谢您抽出宝贵时间回复,很遗憾它不起作用。它和我的代码做的事情是一样的,它只穿过最顶层的框架而不再走。这可能是应用程序本身的设计问题。很抱歉没有包含 JSON 文件。
    • 我的示例以框架开头,但并非必须如此。我已更新答案以使用 CURRENT-WINDOW 作为树的顶部。在您的代码中,我认为您遇到的一个问题是您太容易摆脱困境。在我看来,这些 LEAVE 语句看起来就像它们不允许您的代码完全遍历树,直到它找到它正在寻找的东西。
    • 如果您想要一个比这更准确的答案,我认为您需要提供有关您的窗口及其框架的更多信息......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    相关资源
    最近更新 更多