简体   繁体   English

在设计器中触发Firemonkey自定义控件单击事件

[英]Firemonkey custom control click events firing in designer

I have a custom Firemonkey control that has several sub components. 我有一个具有几个子组件的自定义Firemonkey控件。 These sub components have OnClick events associated with them that are setup in the control's constructor. 这些子组件具有与它们关联的OnClick事件,这些事件在控件的构造函数中设置。 I have noticed that when I click on the custom control in my design view, the OnClick events of these sub components are getting fired. 我注意到,当我在设计视图中单击自定义控件时,将触发这些子组件的OnClick事件。

Is there a particular setting or best practice I need to employ to prevent this from happening? 我需要采用特定的设置或最佳实践来防止这种情况发生吗?

Is there something I can check in my C++ code to see if this event is being run in the designer vs at run time? 我可以在C ++代码中检查一下该事件是否在设计器中运行还是在运行时运行吗? Something like: 就像是:

void __fastcall MyControlOnClick( TObject * Sender )
{
    if( InDesigner == false )
    {
         //do stuff here
    }
}

Use the ComponentState property. 使用ComponentState属性。 It has a csDesigning flag enabled when your control is being used in the Form Designer. 在窗体设计器中使用控件时, csDesigning启用csDesigning标志。

void __fastcall MyControl::SubControlClick(TObject *Sender)
{
    if( !ComponentState.Contains(csDesigning) )
    {
         //do stuff here
    }
}

Alternatively, simply don't assign the OnClick handlers at design-time to begin with: 另外,不要在设计时就从分配OnClick处理程序开始:

__fastcall MyControl::MyControl(TComponent *Owner)
    : TBaseControl(Owner)
{
    ...
    FSubControl = new TWhatever(this);
    if( !ComponentState.Contains(csDesigning) )
        FSubControl->OnClick = &SubControlClick;
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM