Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Firemonkey check in code if in designer or runtime


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Mar 1, 2017 11:29 AM Last Post By: Remy Lebeau (Te...
James Hogle

Posts: 7
Registered: 6/15/15
Firemonkey check in code if in designer or runtime  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2017 9:19 AM
I have a custom control that has several sub components. These components have OnClick events which are set by the control. I am running into an issue where clicking on the control in the designer fires these click events, which I do not want to happen. Is there a way to check in my C++ code if I am in the designer or not? That way I can avoid executing the click event when working on my forms.

Thanks!

Edited by: James Hogle on Mar 1, 2017 9:29 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Firemonkey check in code if in designer or runtime [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2017 11:29 AM   in response to: James Hogle in response to: James Hogle
James wrote:

I have a custom control that has several sub components. These
components have OnClick events which are set by the control. I am
running into an issue where clicking on the control in the designer
fires these click events, which I do not want to happen. Is there a
way to check in my C++ code if I am in the designer or not? That way I
can avoid executing the click event when working on my forms.

Use the ComponentState property:

http://docwiki.embarcadero.com/Libraries/en/System.Classes.TComponent.ComponentState

It has a csDesigning flag enabled when your control is being used in the
Form Designer.

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:

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


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02