Page 1 of 1

Question about automatic disabling childs

Posted: Thu Feb 25, 2010 1:26 am
by Markus Walter
Hello Roger,

is it possible to have automatic disabled childs, if the parent is disabled about his WHEN-Block?

Sample:
I have a DCSTATIC Groupbox with 20 DCGETS on it. Now i would expect, that they are disabled, if the whenblock of the DCSTATIC is .f.
This would help much in complex dialogs.
Is this possible?

Re: Question about automatic disabling childs

Posted: Thu Feb 25, 2010 7:49 am
by rdonnay
This should already work the way you suggest.

Are you saying that it does not?

Re: Question about automatic disabling childs

Posted: Thu Feb 25, 2010 8:15 am
by Markus Walter
Hi Roger,

please test the following:

Code: Select all

#include "dcdialog.ch"

function Appsys()
return NIL

procedure main()
local getlist := {}, getoptions := {}, lRet, oStatic, cVar1 := space(10), cVar2 := (10), cVar3 := (10), lAktiv := .t.

  @ 3,3 DCSTATIC TYPE XBPSTATIC_TYPE_GROUPBOX SIZE 20, 4 OBJECT oStatic WHEN {|| lAktiv}
  @ 1, 1 DCGET cVar1 PARENT oStatic
  @ 2, 1 DCGET cVar2 PARENT oStatic WHEN {|| lAktiv}

  @ 9, 3 DCGET cVar3

  @ 10, 3 DCPUSHBUTTON SIZE 10, 2 CAPTION "um" ACTION {|| if(lAktiv, lAktiv := .f., lAktiv := .t.), dc_getrefresh() }

  DCGETOPTIONS TITLE "Test"
  DCREAD GUI TO lRet OPTIONS getoptions FIT

RETURN
and press the Button. The first DCGET (without his own when clause) will not be disabled.

Re: Question about automatic disabling childs

Posted: Thu Feb 25, 2010 8:34 am
by rdonnay
This appears to be a bug or a limitation of the Xbase++ XbpStatic class.

I tried several tests and could not make it work correctly.

Re: Question about automatic disabling childs

Posted: Thu Feb 25, 2010 9:03 am
by Markus Walter
Hi,

not nice to hear. This would be very handy witj complex screens.

What do you think about the idea to look from the Child: If one of the parent is disabled, it should be diabled, too?

Re: Question about automatic disabling childs

Posted: Thu Feb 25, 2010 9:30 am
by rdonnay
Ok, here is your fix:

Replace the METHOD XbpStatic:WhenHideEval in _DCCLASS.PRG with the below code.
Rebuild dclipx.dll by running build19.bat.

Code: Select all

METHOD DC_XbpStatic:WhenHideEval( lEnable, lShow, lProtect )

LOCAL i, aChildList := ::childList()

IF Valtype(::whenBlock) = 'B'
  lEnable:= Eval(::whenBlock,self)
  IF lEnable
    ::enable()
    FOR i := 1 TO Len(aChildList)
      IF IsMethod(aChildList[i],'whenHideEval')
        IF IsMemberVar(aChildList[i],'whenBlock') .AND. Valtype(aChildList[i]:whenBlock) == 'B'
          aChildList[i]:whenHideEval( lEnable, lShow, lProtect )
        ELSEIF IsMethod(aChildList[i],'enable')
          aChildList[i]:enable()
        ENDIF
      ELSEIF IsMethod(aChildList[i],'enable')
        aChildList[i]:enable()
      ENDIF
    NEXT
  ELSE
    ::disable()
    FOR i := 1 TO Len(aChildList)
      IF IsMethod(aChildList[i],'disable')
        aChildList[i]:disable()
      ENDIF
    NEXT
  ENDIF
ENDIF

IF Valtype(::hideBlock) = 'B'
  lShow := !Eval(::hideBlock,self)
  IF lShow
    IF !::isVisible()
      ::show()
    ENDIF
  ELSE
    IF ::isVisible()
      ::hide()
    ENDIF
  ENDIF
ENDIF

IF Valtype(lProtect) == 'L' .AND. Valtype(::protectBlock) = 'B'
  lProtect := Eval(::protectBlock,self)
ENDIF

RETURN self

Re: Question about automatic disabling childs

Posted: Fri Feb 26, 2010 1:35 am
by Markus Walter
Hello Roger,

thanks. That seems to work. Will this be part of the next build?

Re: Question about automatic disabling childs

Posted: Fri Feb 26, 2010 7:20 am
by rdonnay
Yes, this will be in the next build.