In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

close window when processing = Runtime errors

Xailer English public forum
Responder
Avatar de Usuario
Hurricane
Mensajes: 262
Registrado: Mar Mar 24, 2015 10:21 am
Ubicación: Brasil
Contactar:

close window when processing = Runtime errors

Mensaje por Hurricane »

Hi,
If you close a window during processing, errors can occur at run time. The Xailer should not avoid receiving clicks?
The close method will destroy the helper objects (items), and the processing has not been completed. Simple example:

Código: Seleccionar todo

METHOD Timer1Timer( oSender ) CLASS TForm1
   local nPos
   
   ::oTimer1:Disable()
   Application:lBusy:=.t. // and CursorWait - does not work, disable the window, temporary solution
   ::oStatusBar1:aItems[5]:cText:='Processing .... close the window now, crash'
   for nPos:=1 to 4
      ::oStatusBar1:aItems[nPos]:cText:=Str(nPos) // line 41 / Error
      ProcessMessages()
      Sleep(1000)
      ProcessMessages()
      Sleep(1000)
   next
   
   AEval(::oStatusBar1:aItems, {|o|o:cText:=''})
   
   Application:lBusy:=.f.
   ::oTimer1:Enable()
   RETURN Nil

Resume:
  • Versão do Xailer: Xailer 4.0.2
    Compilador: Harbour 3.2.0dev (r1503071916)
    Compilador C/C++ : MinGW GNU C 4.9.2 (32-bit)

    Chamada Subsistema: BASE
    Código Sistema: 1132
    Status por Defeito: .F.
    Descrição: Bound error
    Operação: array access
    Argumentos: [ 1] = Tipo: A Val: [ 2] = Tipo: N Val: 2
    Ficheiros envolvidos:
    Dos Error Code: 0

    Trace Through:
    TFORM1:TIMER1TIMER (41)
    TTIMER:ONTIMER (0)
    (b)XTIMER (43)
    TTIMER:WMTIMER (0)
    RUNFORM (0)
    TAPPLICATION:RUN (287)
    MAIN (15)
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9252
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: close window when processing = Runtime errors

Mensaje por ignacio »

Hello,

In my opinion your code is due the following:

1) Sleep() should almost never be used

2) A single ProcessMessages() at the beginning and end of the function should be enough

3) On your loop you are not controlling if the window is closing

This should work:

oTimer:Disable()
Application:lBusy := .t.
ProcessMessages()
AEval(oStatusBar1:aItems, {|o|... })
ProcessMessages()
Application:lBusy := .f.
oTimer:Enable()

In case you need that second delay between statusbar items operation. Consider the use of a timer with a interval of 1000 and set only one statusbar item at a time.

Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Avatar de Usuario
Hurricane
Mensajes: 262
Registrado: Mar Mar 24, 2015 10:21 am
Ubicación: Brasil
Contactar:

Re: close window when processing = Runtime errors

Mensaje por Hurricane »

Hi, good Morning :)
This is one of the examples to demonstrate a serious fact Xailer. The problem occurs in any code to use objects that window was closed, of course, because the process is still continuing, are expected facts.

But independent of any code, you agree that Xailer should not allow clicks when using lBusy:. = .T. or CursorArrow? In a typical process, we will not give the user the option to stop (by click or key). In these cases is simply an alternative to this Xailer behavior, avoiding extra code.

In the rare instances that we have a process in infinite loop or allow interrupt a process, it is natural that we should use "flags, try, if" in the processing and events.
In my routine will not give errors by knowing Xailer behavior. If you make a simple code in Lazarus (Delphi) you'll see that does not have this feature (Click).

regards,
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9252
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: close window when processing = Runtime errors

Mensaje por ignacio »

Hello,

I absolutely do not agree, sorry 8-)

The function ProcessMessages() what it really does it TO ALLOW MESSAGES TO BE PROCESSED. SO:

Is your duty as an expert programmer to avoid the clicking of buttons or closing the form. This issue it has been commented MANY, MANY, MANY, ...... TIMES in this forum.

SO, you must controll this issue and I propose the following:

1) Disabling any control that may conflict

2) Disabling the form or use a private member TForm:lWorking to avoid closing the form when your routine is working.

3) I personally change the action of the default button to cancel the routine if possible. For that I create another TForm member with the name lCancel. The action of the button just changes lCancel to .T. and of course you should control the value of ::lCancel on your routine loop.

That's all!!!!

Thread closed.

Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Responder