Página 1 de 1

close window when processing = Runtime errors

Publicado: Jue Oct 01, 2015 11:36 pm
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)

Re: close window when processing = Runtime errors

Publicado: Vie Oct 02, 2015 10:09 am
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,

Re: close window when processing = Runtime errors

Publicado: Vie Oct 02, 2015 3:26 pm
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,

Re: close window when processing = Runtime errors

Publicado: Vie Oct 02, 2015 5:02 pm
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,