2008-04-18

Dynamic enabled() property for StringEdit and arrows

Sometimes we need to enable or disable some field depending on value from another field.

The first way is using Group object where FrameOptionButton property is set to Check. For details see \Forms\tutorial_Form_groupOption

The second approach is setting enabled() property for StringEdit object.

void enableControls()
{
    StringEdit_1.enabled(myTable.Field);
}

Unfortunately we may notice that the arrow object of StringEdit doesn't work properly. Sometimes the arrow is vanish away from control.

The small modification should improve the arrow's behaviour.

In fact the arrow is the child window of StringEdit. The idea consists in managing state of parent and child window trough winApi.

All what we need to do is:

1. Add new enableWindow() method in WinApi class:

// Created by GRR
client static boolean enableWindow(int _handle, boolean _value)
{
    DLL         _DLL             = new DLL('USER32');
    DLLFunction _enableWindow    = new DLLFunction(_DLL, 'EnableWindow');

    _enableWindow.returns(ExtTypes::DWord);
    _enableWindow.arg(ExtTypes::DWord);
    _enableWindow.arg(ExtTypes::DWord);

    return _enableWindow.call(_handle, _value);
}

2. Rewrite our enableControls() method:

void enableControls()
{
    void controlEnabled(FormControl control, boolean _value)
    {
        #WinApi

        int ctrlHwnd    = control.hWnd();
        int childHwnd   = WinApi::getWindow(ctrlHwnd, #GW_CHILD);
        ;

        WinApi::showWindow(ctrlHwnd, #SW_SHOW);
        WinApi::showWindow(childHwnd, #SW_SHOW);

        WinApi::enableWindow(ctrlHwnd,  _value);
        WinApi::enableWindow(childHwnd, _value);
    }
    ;

    controlEnabled(StringEdit_1,   myTable.Field);
    controlEnabled(StringEdit_2,   myTable.Field);
}

AX 3.0 SP4

Copyright © 2008 Ruslan Goncharov

No comments: