Page 1 of 1

DISABLE / ENABLE a button on a form

Posted: Wed Apr 05, 2023 7:53 pm
by Red2
Hello all,

Can someone with more HMG experience please explain why I cannot DISABLE and later ENABLE a button on a form?
This should be a simple question.
The confusing thing is that similar code works as expected in HMG_Extended.

Google Translation:
¿Puede alguien con más experiencia en HMG explicar por qué no puedo DISABLE y luego ENABLE un botón en un formulario?
Esta debería ser una pregunta simple.
Lo confuso es que un código similar funciona como se esperaba en HMG_Extended.

Thank you. I really appreciate any help.

Re: DISABLE / ENABLE a button on a form

Posted: Wed Apr 05, 2023 9:04 pm
by andyglezl
Red2 wrote: Wed Apr 05, 2023 7:53 pm Hello all,

Can someone with more HMG experience please explain why I cannot DISABLE and later ENABLE a button on a form?
This should be a simple question.
The confusing thing is that similar code works as expected in HMG_Extended.

Google Translation:
¿Puede alguien con más experiencia en HMG explicar por qué no puedo DISABLE y luego ENABLE un botón en un formulario?
Esta debería ser una pregunta simple.
Lo confuso es que un código similar funciona como se esperaba en HMG_Extended.

Thank you. I really appreciate any help.

Tu programa funciona bien en HMG...
Si comentas las siguientes líneas, verás que queda "DISABLED"...
*----------------------------------------------------------------------------------------
Your program works fine in HMG...
If you comment out the following lines, you will see that "DISABLED" remains...


*** SetProperty( "Main", "btnRun", "Enabled", .T. ) /* <---- ???? ---- */
*** Main.btnRun.Enabled := .T. /* <---- ???? ---- */

Re: DISABLE / ENABLE a button on a form

Posted: Wed Apr 05, 2023 9:45 pm
by Red2
Hi andyglez,

GOOGLE TRANSLATION:
Gracias por su rápida respuesta.

Sí, la eliminación de esas dos líneas hace que el button se disabled, pero solo DESPUÉS de que finalice su procesamiento.
Durante el procesamiento, el botón NO está deshabilitado (cuando en realidad lo necesito).

Necesito el botón deshabilitado DURANTE su procesamiento de ACTION EVENT.
Nota: Está correctamente deshabilitado en HMG Extended.

---------------------------------------------
Thank you for your prompt response.
Yes, removal of those two lines results in the button being disabled but only AFTER the its processing is finished.
During the processing the button is NOT disabled (when actually I need it).

I need the button disabled DURING its ACTION EVENT processing.
Note: It is correctly disabled in HMG Extended.

QUESTION:
Can button deactivation happen during its processing in "Official" HMG?

Thank you!
Red2

Re: DISABLE / ENABLE a button on a form

Posted: Wed Apr 05, 2023 11:15 pm
by andyglezl
"I need the button disabled DURING its ACTION EVENT processing."


Con el Do - While que tienes y el MSGINFO(), tu botón está DISABLE hasta que termine y oprimas el botón de "Aceptar"
no necesitas los SetProperty()
*-----------------------------------------------------------------------------------------------------------------------------------------------
With the Do - While you have and the MSGINFO(), your button is DISABLE until it finishes and you press the "OK" button
you don't need the SetProperty()


*** SetProperty( "Main", "btnRun", "Enabled", .F. ) /* <---- ???? ---- */
*** Main.btnRun.Enabled := .F. /* <---- ???? ---- */
DO WHILE seconds() < lnEnd
lnIterations +=1
ENDDO
*** SetProperty( "Main", "btnRun", "Enabled", .T. ) /* <---- ???? ---- */
*** Main.btnRun.Enabled := .T. /* <---- ???? ---- */
msgInfo( )

Re: DISABLE / ENABLE a button on a form

Posted: Thu Apr 06, 2023 3:47 am
by Red2
Hi andyglezl,

GOOGLE TRANSLATION:
Gracias por su sugerencia muy amable.
Incluso cuando se elimina MsgInfo(), el botón no deactivate durante el DO WHILE loop.
Además, MsgInfo() viene DESPUÉS del bucle DO WHILE...ENDDO, por lo que no está causando problemas.

¿Qué puedo hacer para DESHABILITAR un botón durante el tiempo que está ejecutando el código en su ACTION Event?
Mi código de ejemplo simple de HMG demuestra el problema, al menos en mi computadora.

¿Esto no es posible en Official HMG o simplemente me estoy perdiendo algo?

-------------------------------------------------
Thank you for your very kind suggestion.
Even when MsgInfo() is removed, the the button does not deactivate during the DO WHILE loop.
Also, the MsgInfo() comes AFTER the DO WHILE...ENDDO loop so it is not causing my issue.

What can I do to DISABLE a Button during the time it is running code in its ACTION Event?
My simple HMG example code demonstrates the problem, at least on my computer.

Is this not possible in Official HMG or am I simply missing something?

Thanks again,
Red2

Re: DISABLE / ENABLE a button on a form

Posted: Thu Apr 06, 2023 4:03 am
by andyglezl
:roll: Ni se si con DISABLE te refieras a que el Botón se cambie a gris
o que no ejecute nada.
Porque así como está, por más que le des "click" no ejecutará nada hasta que termine el Do-While
*------------------------------------------------------------------------------------------------------------------------
:roll: I don't even know if by DISABLE you mean that the Button turns gray
Or do not execute anything.
Because as it is, no matter how much you "click" it, it will not execute anything until the Do-While ends


Quizá este post te pueda servir...
*--------------------------------------------
Maybe this post can help you...

viewtopic.php?p=57887#p57887

Re: DISABLE / ENABLE a button on a form

Posted: Thu Apr 06, 2023 7:01 am
by edk
Guys, finally learn that to make your HMG application responsive while executing long-acting loops (DO WHILE, FOR ... NEXT, etc) you must ALWAYS use the DO EVENTS command inside the loop. Note, since each call to DO Events slows down the loop, it's best to execute this command every n-th step in the loop.
Try setting the loop time to 50 seconds without the Do Events command and see that while the loop is running, the program will stop responding, you won't be able to move the main window or close it normally. All you have to do is do Do Events in the loop and the application will start behaving as usual.
That's all there is to this topic.

Code: Select all

DO WHILE seconds() < lnEnd
	IF lnIterations%10000 = 0
		DO Events
	ENDIF
	lnIterations ++
ENDDO

Re: DISABLE / ENABLE a button on a form

Posted: Thu Apr 06, 2023 7:53 am
by serge_girard
Thanks EDK! Hope this will solve many problems!

Serge

Re: DISABLE / ENABLE a button on a form

Posted: Thu Apr 06, 2023 1:56 pm
by Red2
Thank you EDK,

I really appreciate you kindly sharing your expertise!!!
Your suggestion informs the user with the visual appearance I wanted.

Thanks again,
Spencer