0

I have a custom Firemonkey control that has several sub components. These sub components have OnClick events associated with them that are setup in the control's constructor. 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.

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? Something like:

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

1 回答 1

2

使用该ComponentState物业。csDesigning当您的控件在表单设计器中使用时,它启用了一个标志。

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

或者,简单地不要OnClick在设计时分配处理程序:

__fastcall MyControl::MyControl(TComponent *Owner)
    : TBaseControl(Owner)
{
    ...
    FSubControl = new TWhatever(this);
    if( !ComponentState.Contains(csDesigning) )
        FSubControl->OnClick = &SubControlClick;
    ...
}
于 2017-03-01T19:11:55.647 回答