Board index » cppbuilder » Link Action->Checked with CheckBox and SpeedButton

Link Action->Checked with CheckBox and SpeedButton

Is possible to syncronize the Checked property of an Action associated with
a CheckBox ?
And with a SpeedButton with the Down property (the Button can be in the
pressed state) ?
 

Re:Link Action->Checked with CheckBox and SpeedButton


Quote
"nick" <nicolazan...@inwind.it> wrote in message news:3c863594_1@dnews...
> Is possible to syncronize the Checked property of an Action associated
with
> a CheckBox ?

Simply assign your Action to the Action property of the CheckBox.  Then
every time Action->Checked changed, so will CheckBox->Checked

Quote
> And with a SpeedButton with the Down property (the Button can be in the
> pressed state) ?

If you want the Action->Checked property to control the SpeedButton->Down
property, it won't.  You'll still have to do that manually.  Or else you can
try deriving a decendant from TSpeedButton so you can override the inherited
ActionChange() method to respond to the Action's change accordingly.

Gambit

Re:Link Action->Checked with CheckBox and SpeedButton


Quote
> > Is possible to syncronize the Checked property of an Action associated
> with
> > a CheckBox ?

> Simply assign your Action to the Action property of the CheckBox.  Then
> every time Action->Checked changed, so will CheckBox->Checked

I've tried. It's work when the Action->Checked changes, then the
CheckBox->Checked changes, but when I click on the CheckBox, the
Action->Checked is not updated. Only OnExecute event is fired.

Quote

> > And with a SpeedButton with the Down property (the Button can be in the
> > pressed state) ?

> If you want the Action->Checked property to control the SpeedButton->Down
> property, it won't.  You'll still have to do that manually.  Or else you
can
> try deriving a decendant from TSpeedButton so you can override the
inherited
> ActionChange() method to respond to the Action's change accordingly.

Ok, for the CheckBox and SpeedButton, I've derived a component with a method
like this:

void __fastcall NewSpeedButton::ActionChange(System::TObject* Sender, bool
CheckDefaults) {
    if( Action ) {
        TAction* a = dynamic_cast<TAction*>(Action);
        if( a ) Down = a->Checked;
    };
    TSpeedButton::ActionChange(Sender,CheckDefaults);

Quote
};

It works.

Re:Link Action->Checked with CheckBox and SpeedButton


Quote
"nick" <nicolazan...@inwind.it> wrote in message news:3c8737a7_2@dnews...
> I've tried. It's work when the Action->Checked changes, then the
> CheckBox->Checked changes, but when I click on the CheckBox, the
> Action->Checked is not updated. Only OnExecute event is fired.

This is by design.  Actions update controls, not the other way around.

Quote
> Ok, for the CheckBox and SpeedButton, I've derived a component with a
method
> like this:

It probably should be more like this instead, for consistency with the rest
of the VCL:

    void __fastcall NewSpeedButton::ActionChange(System::TObject* Sender,
bool CheckDefaults)
    {
        TSpeedButton::ActionChange(Sender, CheckDefaults);

        TCustomAction *CAction = dynamic_cast<TCustomAction*>(Sender);
        if( CAction )
        {
            if( !CheckDefaults || this->Down == false)
                this->Down = CAction->Checked;
        }
    }

Gambit

Other Threads