Page 1 of 1

problems with radio and radioitem

PostPosted: Tue Jul 14, 2015 3:11 pm
by aferra
Guys ... I'm tweaking some functions and realized that the radio (standing inside a folder, in a dialog works correctly) to choose an option passes twice in the function, and this is causing me slowly to select the records because two processes times the while, is to fix this?

working example:
Code: Select all  Expand view

DEFINE DIALOG oDlg FROM 0,0 TO 520,820 PIXEL
 
  @ 000,195 GROUP TO 045,335 LABEL "Tipo do Relatório" PIXEL TRANSPARENT OF oDlg
  @ 007,195 RADIO oTipo VAR nTipo PROMPT "Tabela de Preço", "Tabela de Promoção", "Lista de Compra", "Lista de Compra Ideal" SIZE 65,9 PIXEL ON CHANGE Troca() OF oDlg
  @ 007,265 RADIOITEM "Sugestão de Compra" RADIOMENU oTipo SIZE 65,08 PIXEL OF oDlg
  @ 016,265 RADIOITEM "Estoque Mínimo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oDlg
  @ 025,265 RADIOITEM "Estoque Negativo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oDlg
  @ 034,265 RADIOITEM "Estoque Positivo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oDlg
 
 ACTIVATE DIALOG oDlg CENTER
 
RETURN NIL
 


example with problem
Code: Select all  Expand view

DEFINE DIALOG oDlg FROM 0,0 TO 520,820 PIXEL
 
  @ 90,03 FOLDER oFld OF oDlg PROMPT "&Produto","&Movimentação","&Valores" ;
    PIXEL SIZE 405,208
 
  @ 000,195 GROUP TO 045,335 LABEL "Tipo do Relatório" PIXEL TRANSPARENT OF oFld:aDialogs[1]
  @ 007,195 RADIO oTipo VAR nTipo PROMPT "Tabela de Preço", "Tabela de Promoção", "Lista de Compra", "Lista de Compra Ideal" SIZE 65,9 PIXEL ON CHANGE Troca() OF oFld:aDialogs[1]
  @ 007,265 RADIOITEM "Sugestão de Compra" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
  @ 016,265 RADIOITEM "Estoque Mínimo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
  @ 025,265 RADIOITEM "Estoque Negativo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
  @ 034,265 RADIOITEM "Estoque Positivo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
 
 ACTIVATE DIALOG oDlg CENTER
 
RETURN NIL
 


Code: Select all  Expand view

function Troca()
?"with folder passes twice" + CRLF + "with dialog passes once"
RETURN
 


thank you

Re: problems with radio and radioitem

PostPosted: Tue Jul 14, 2015 10:26 pm
by James Bott
Aferra,

I think what you are seeing is that you are changing focus from the folder to the message, then back to the folder. So, it appears to be getting called twice.

I tried the test code below and changed the Troca() function to write to a log file (test.log) each time it is called. It only logs one time.

Also I am not seeing any slowdown--it is very fast.

James

Code: Select all  Expand view
/*
Purpose  : Test calling of function by radion buttons
Author   : Aferra, Modified by James Bott
Date     : 7/14/2015 3:06:11 PM
Language : Fivewin/xHarbour
Updated  :
Notes    :

*/


#include "fivewin.ch"

Function Main()

   LOCAL oDlg, oFld, nTipo:=1, oTipo

   DEFINE DIALOG oDlg FROM 0,0 TO 520,820 PIXEL
 
   @ 90,03 FOLDER oFld OF oDlg PROMPT "&Produto","&Movimentação","&Valores" ;
    PIXEL SIZE 405,208
 
   @ 000,195 GROUP TO 045,335 LABEL "Tipo do Relatório" PIXEL TRANSPARENT OF oFld:aDialogs[1]
   @ 007,195 RADIO oTipo VAR nTipo PROMPT "Tabela de Preço", "Tabela de Promoção", "Lista de Compra", "Lista de Compra Ideal" SIZE 65,9 PIXEL ON CHANGE Troca() OF oFld:aDialogs[1]
   @ 007,265 RADIOITEM "Sugestão de Compra" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
   @ 016,265 RADIOITEM "Estoque Mínimo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
   @ 025,265 RADIOITEM "Estoque Negativo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
   @ 034,265 RADIOITEM "Estoque Positivo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
 
 ACTIVATE DIALOG oDlg CENTER
 
RETURN NIL

function Troca()
   //?"with folder passes twice" + CRLF + "with dialog passes once"
   logfile("test.log",{"Troca()"})
RETURN

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 1:25 am
by Euclides
I confirm the problem
Code: Select all  Expand view

Function Main()
   LOCAL oDlg, oFld, nTipo:=1, oTipo

   DEFINE DIALOG oDlg FROM 0,0 TO 520,820 PIXEL
   @ 90,03 FOLDER oFld OF oDlg PROMPT "&Produto","&Movimentação","&Valores"   PIXEL SIZE 405,208
   @ 000,195 GROUP TO 045,335 LABEL "Tipo do Relatório" PIXEL TRANSPARENT OF oFld:aDialogs[1]
   @ 007,195 RADIO oTipo VAR nTipo PROMPT "Tabela de Preço", "Tabela de Promoção", "Lista de Compra", ;
                   "Lista de Compra Ideal"    SIZE 65,9 PIXEL ON CHANGE Troca(nTipo) OF oFld:aDialogs[1]
   @ 007,265 RADIOITEM "Sugestão de Compra" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
   @ 016,265 RADIOITEM "Estoque Mínimo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
   @ 025,265 RADIOITEM "Estoque Negativo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
   @ 034,265 RADIOITEM "Estoque Positivo" RADIOMENU oTipo SIZE 65,08 PIXEL OF oFld:aDialogs[1]
   ACTIVATE DIALOG oDlg CENTER
RETURN NIL

function Troca(nTipo)
   logfile("test.log",{str(nTipo)})
RETURN nil
 

3 line-down gives:
07/14/15 22:18:09: 2
07/14/15 22:18:09: 2
07/14/15 22:18:10: 3
07/14/15 22:18:10: 3
07/14/15 22:18:10: 4
07/14/15 22:18:10: 4
:cry: Euclides

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 9:05 am
by AntoninoP
I tried it too,
Here the stacks: the top one is without the folder, the bottom two are with the folder.
Image
here TRadMenu:Refresh():
Code: Select all  Expand view
METHOD Refresh() CLASS TRadMenu

   local nOption := Eval( ::bSetGet )
   local nAt     := AScan( ::aItems, { | oRadio | If( oRadio != nil, oRadio:lIsChecked(), .f. ) } )

   DEFAULT nOption := 1

   if nAt != nOption .and. nAt <= Len( ::aItems ) .and. Len( ::aItems ) > 0
      if nAt != 0
         ::aItems[ nAt ]:SetCheck( .f. )
      endif
      if ::aItems[ nOption ] != nil
         ::aItems[ nOption ]:SetCheck( .t. )
      endif
      if ::bChange != nil
         Eval( ::bChange, Self )
      endif
   endif

return nil

looks like in the case with folder, the click is called before than lIsCheckd returns true so nAt is not the new nOption, :?: :?:

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 11:57 am
by Antonio Linares
Euclides,

I just tested your example with FWH 15.05 and I get this in the test.log:

07/15/15 13:55:39: 2
07/15/15 13:55:42: 3
07/15/15 13:55:48: 4

Antonino,

Are you testing Euclides example ?

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 12:05 pm
by aferra
I thank all the answers.

Antonio, You suggest that update refresh the radio?

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 12:10 pm
by Antonio Linares
I simply tested Euclides example and it worked fine with FWH 15.05

Is there any other example that you would like me to test ?

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 12:37 pm
by aferra
well, I moved the test to logfile () and believe me, this passing only once, now put this structure gives the error.

example

aArray: = {}

while eof ()
    AADD (aArray ....)
    skip
ENDDO

if I comment this line aArray: = {} my array doubles the data, I am confused now. :)

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 12:47 pm
by aferra
I found the problem.

after while ... ENDDO have a msgyesno (), taking this msg () does not happen the problem, the logfiile shows only once passing within the function.

what to do?

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 4:51 pm
by Antonio Linares
Before calling:

msgyesno()

Try this:

oDlg:Disable()

and after the msgyesno():

oDlg:Enable()

Re: problems with radio and radioitem

PostPosted: Wed Jul 15, 2015 6:07 pm
by aferra
YES,

It worked perfectly, was already thinking about changing the screen to get the result, but now everything in order and with a simple solution ...

thank you Antonio