C++builder 如何检查组件是否为c+中的TEdit类型+;建设者

C++builder 如何检查组件是否为c+中的TEdit类型+;建设者,c++builder,vcl,C++builder,Vcl,如何检查表单的所有组件并验证组件是否为类型TEdit?您可以使用 您可以使用 如果我错了,请原谅,embarcadero不会自动将所有表单组件对象指针添加到类定义中(在头文件中) 例如: class TFormSomeForm : public TForm { __published: TEdit *SomeEditBox; TEdit *AnotherEditBox; ... } 这意味着您可以从标题中辨别哪些组件属于TEdit类型。 或者,您可以单击“设计”视图中的组件,对

如何检查表单的所有组件并验证组件是否为类型
TEdit

您可以使用

您可以使用

如果我错了,请原谅,embarcadero不会自动将所有表单组件对象指针添加到类定义中(在头文件中)

例如:

class TFormSomeForm : public TForm
{
__published:
    TEdit *SomeEditBox;
    TEdit *AnotherEditBox;
...
}
这意味着您可以从标题中辨别哪些组件属于TEdit类型。

或者,您可以单击“设计”视图中的组件,对象检查器将显示类型。

如果我错了,请原谅,但embarcadero不会自动将所有表单组件对象指针添加到类定义中(在头文件中)

例如:

class TFormSomeForm : public TForm
{
__published:
    TEdit *SomeEditBox;
    TEdit *AnotherEditBox;
...
}
这意味着您可以从标题中辨别哪些组件属于TEdit类型。

或者,您可以单击“设计”视图中的组件,对象检查器将显示类型。

My function设置TWinControl及其子控件中所有编辑的文本属性

void __fastcall SetEditsText(TWinControl* winControl, UnicodeString editsText)
{    
    for (int c = 0; c < winControl->ControlCount; c++)
    {
        TControl* ctrl = winControl->Controls[c];

        TWinControl* wc = dynamic_cast<TWinControl*>(ctrl);

        // Check if it's grouping component
        if (wc != NULL)
        {
            // Set edits of children
            SetEditsText(wc, editsText);
        }
        else 
        {
            if (ctrl->ClassType() == __classid(TEdit))
            {
                TEdit* ecomp = (TEdit*) ctrl;
                ecomp->Text = editsText;
            }
        }
    }
}

My函数设置TWinControl及其子控件中所有编辑的文本属性

void __fastcall SetEditsText(TWinControl* winControl, UnicodeString editsText)
{    
    for (int c = 0; c < winControl->ControlCount; c++)
    {
        TControl* ctrl = winControl->Controls[c];

        TWinControl* wc = dynamic_cast<TWinControl*>(ctrl);

        // Check if it's grouping component
        if (wc != NULL)
        {
            // Set edits of children
            SetEditsText(wc, editsText);
        }
        else 
        {
            if (ctrl->ClassType() == __classid(TEdit))
            {
                TEdit* ecomp = (TEdit*) ctrl;
                ecomp->Text = editsText;
            }
        }
    }
}

在很多情况下,可能需要动态迭代表单或其他容器的控件,或者检查分配给多个组件的公共事件处理程序的发送方类型,因此,能够在运行时动态确定组件的类类型确实有用处。在很多情况下,可能需要动态迭代表单或其他容器的控件,或者检查分配给多个组件的公共事件处理程序的发送方的类型,因此,能够在运行时动态确定组件的类类型是有用途的。不要忘记,如果强制转换是非法的,动态\u强制转换可以抛出std::bad \u强制转换。若在引用上使用,则应将此代码包装在try/catch.dynamic_cast抛出异常中,但若在指针上使用,则将返回null。(“…如果在指针上使用动态\u转换,则返回类型为new\u type的空指针值。如果在引用上使用,则会引发异常std::bad\u转换…”)不要忘记,如果转换非法,动态\u转换可以引发std::bad\u转换。若在引用上使用,则应将此代码包装在try/catch.dynamic_cast抛出异常中,但若在指针上使用,则将返回null。(“…如果在指针上使用动态\u转换,则返回类型为new\u type的空指针值。如果在引用上使用该值,则引发异常std::bad\u转换…”)