AX2009循环通过init的形式的所有控件 [英] AX2009 Loop through all the controls in the form on init

查看:232
本文介绍了AX2009循环通过init的形式的所有控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在初始化和运行方法中,我尝试过以下操作,但是它不工作:

  for(i = 1; i< = element.form()。design()。controlCount (); i ++)
{
control = element.form()。design()。controlNum(i);

switch(control.handle())
{
case classnum(FormBuildButtonControl):
element.initButton(control);
break;
case classnum(FormBuildStaticTextControl):
element.initStaticText(control);
break;
}
}

有没有办法这样做? >

解决方案

您有效的代码,但它只能遍历设计的顶层。您需要构建一个递归函数来迭代整个控件集,并将其放在init()之前的 之前。

  void init()
{
int i;
void processControls(FormBuildControl fbc)
{
int j;
;

if(fbc.isContainer())
{
for(j = 1; j< fbc.controlCount(); j ++)
{
//处理容器,如果需要
processControls(fbc.controlNum(j));
}
}
else
{
//控件不是容器,在此处处理。
}
}
; (i = 1; i <= element.form()。design()。controlCount(); i ++)
{
processControls(element.form() .design()。controlNum(i);
}

super();
}

super()调用将自动初始化表单上的所有控件,一旦初始化,您将无法使用 FormBuildControl 键入对象以配置字段,因为它们已经被使用到表单上。如果您需要在初始化后修改该字段,则应直接引用该字段(尽管我不确定如何获取该字段名称,并通过X ++引用它)。



而不是有条件地初始化控件,请调用super()并简单地有条件地隐藏该字段,或使用安全性隐藏信息,



编辑:
由于您正在处理 FormBuildControl s,这是预先初始化的设计后,应该在初始化processControl调用后再调用super()。我改变了我的例子来反映这一点。


How is it possible to loop through all the controls in a form when a form is initialized?

I have tried the following in the init and run methods, but it does not work:

for( i = 1 ; i <= element.form().design().controlCount() ; i++ )
{
    control = element.form().design().controlNum(i);

    switch ( control.handle() )
    {
        case classnum(FormBuildButtonControl):
            element.initButton(control);
        break;
        case classnum(FormBuildStaticTextControl):
            element.initStaticText(control);
        break;
    }
}

Is there any way of doing this?

解决方案

The code you have works, but it only iterates through the top level of the design. You need to build a recursive function to iterate through the entire set of controls, and place it in the init method before the super():

void init()
{
    int     i;
    void    processControls(FormBuildControl fbc)
    {
        int     j;
        ;

        if (fbc.isContainer())
        {
            for (j = 1; j < fbc.controlCount(); j++)
            {
                //Process container, if you need to
                processControls(fbc.controlNum(j)); 
            }
        }
        else
        {
            //Control is not a container, process it here.                
        }
    }
    ;

    for (i = 1; i <= element.form().design().controlCount(); i++)
    {
        processControls(element.form().design().controlNum(i);
    }

    super();
}

The super() call will automatically initialize all the controls on the form. Once they are initialized, you won't be able to use FormBuildControl type objects to configure the fields, as they will already be consumed onto the form. If you need to modify the field after initialization, you should refer to the field directly (though I'm unsure of how you could get the field name and reference it via X++).

Instead of conditionally initializing the controls, call super() and simply hide the field conditionally, or use security to hide information you don't want certain people to have access to.

EDIT: Since you are dealing with FormBuildControls, which are pre-initialized designs, you should have the super() call after the initial processControls call. I've changed my example to reflect this.

这篇关于AX2009循环通过init的形式的所有控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆