Bug in TBTNBMP Class FWH 19.12 ?

Bug in TBTNBMP Class FWH 19.12 ?

Postby Cgallegoa » Sat Feb 15, 2020 11:57 pm

Hello friends:

In the following example, a dialog is created with a radio and two buttons: one to "select" and the other to "cancel" the task without processing anything after the dialog. That is, what follows after the dialog should only be processed if you click on the "Select" button.

The lSelecc variable is initialized as .F. and will only change to .T, if the "Select" button is pressed.

In other words, if you close the dialog with any of the four options other than "Select" (they are: 1.- ESC key, 2.- click on the "Cancel" button, 3.- click on the "X "in the upper right corner of the dialog, and 4.- Press the ALT+F4 keys to close the dialog), the variable" lSelecc "should remain in .F.

This condition is met in the first three cases, but fails in 4 (ALT+F4) that puts the variable in .T. as if you had clicked on the "Select" button.

This happens only with the TBTNBMP class. With the other classes for button handling everything is going well.

How can I fix it or what should I correct in the class? I urgently need to solve it because the process in which this scenario is involved is highly sensitive to the integrity of the client's data.

Thanks in advance for your extraordinary help.

Code: Select all  Expand view  RUN
#include "FiveWin.ch"

Function Main()
  LOCAL oDlg, oBtn1, oBtn2, oRad, nOpr:=1
  LOCAL lSelecc:=.F. , lNoEsc := .F.
  LOCAL aItems := {"Opcion 1","Opcion 2","Opcion 3","Opcion 4","Opcion 5"}

  DEFINE DIALOG oDlg FROM 0,0 TO 176,245 PIXEL TITLE "Documentos a Reversar" TRANSPARENT

    @ 05, 30 SAY "Seleccione tipo documento:" OF oDlg PIXEL SIZE 100,08

    oRad := TRadMenu():New( 15,25,aItems,{|u|If(PCount()==0,nOpR,nOpR:=u)}, oDlg,,,,,,.F.,, 70 , 09,,.F.,.F.,.T.)

    @ 68,08 BTNBMP oBtn1 PROMPT "&Select" ACTION ( lNoEsc := .T. , lSelecc:=.T. , oDlg:End()) OF oDlg SIZE 48,14 PIXEL;
            LEFT NOBORDER

    @ 68,67 BTNBMP oBtn1 PROMPT "&Cancel" ACTION ( lNoEsc := .T. , lSelecc:=.F. , oDlg:End()) OF oDlg SIZE 48,14 PIXEL;
            LEFT NOBORDER

  ACTIVATE DIALOG oDlg CENTERED VALID lNoEsc
  if lSelecc
     MsgInfo(nOpr)     // <=== *** THIS MUST BE PROCESSED IF, AND ONLY IF, WE CLICK ON THE "SELECT" BUTTON. *** //
  endif
Return(NIL)
Saludos,

Carlos Gallego

*** FWH-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 494
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Bug in TBTNBMP Class FWH 19.12 ?

Postby nageswaragunupudi » Sun Feb 16, 2020 1:41 pm

Very interesting.

Even more interesting is this. Change the prompt of oBtn1 as "&OK" or "&Choose" or any other text. Then ALT-F4 does not close the dialog.

Further, even much more interesting is that if you remove "&" and keep the prompt as "Select" or keep ampersand before any letter other than 's', i.e., "Se&lect", then also ALT-F4 does not close the dialog.

Looks like ALT-F4 is also sending ALT-S to the dialog.

If we use &S in the prompt of any button, that button click is activated by ALT-F4.

This problem is not with BUTTON class.

This is an issue which we need to study carefully and fix the problem.

Meanwhile, this is a temporary workaround for you:

Please remove "&" before "S" in the prompt.
If you want you can keep the "&" before any other letter, eg. "Se&lect"
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Bug in TBTNBMP Class FWH 19.12 ?

Postby Cgallegoa » Sun Feb 16, 2020 3:32 pm

Nages thanks for your reply.

In fact, the issue is related to the union of the accelerator symbol "&" with the letter "S" and the combination "ALT+F4".

With any other letter it works without problems, it is only when "&S" is contained in the prompt of the button.

At the moment I will follow your suggestion temporarily. We have to find the final solution, because I would have to change in many places within the applications

If you check this thread, you will see that it is an old problem, reported by Oscar A. Martinez in 2009, and still not solved !

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=15422&hilit=acelerador

Regards,
Saludos,

Carlos Gallego

*** FWH-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 494
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Bug in TBTNBMP Class FWH 19.12 ?

Postby nageswaragunupudi » Sun Feb 16, 2020 3:55 pm

I agree with you.
We need to find a final solution.
We will look into this.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Bug in TBTNBMP Class FWH 19.12 ?

Postby MaxP » Mon Feb 17, 2020 7:33 am

Hi Carlos,

I propose you to modify your source as below

Code: Select all  Expand view  RUN
   Function Main()
      LOCAL oDlg, oBtn1, oBtn2, oRad, nOpr:=1
      LOCAL lSelecc:=.F. , lNoEsc := .F.
      LOCAL aItems := {"Opcion 1","Opcion 2","Opcion 3","Opcion 4","Opcion 5"}

      DEFINE DIALOG oDlg FROM 0,0 TO 176,245 PIXEL TITLE "Documentos a Reversar" TRANSPARENT

        @ 05, 30 SAY "Seleccione tipo documento:" OF oDlg PIXEL SIZE 100,08

        oRad := TRadMenu():New( 15,25,aItems,{|u|If(PCount()==0,nOpR,nOpR:=u)}, oDlg,,,,,,.F.,, 70 , 09,,.F.,.F.,.T.)

        @ 68,08 BTNBMP oBtn1 PROMPT "&Select" ACTION ( lNoEsc := .T. , lSelecc:=.T. , oDlg:End()) OF oDlg SIZE 48,14 PIXEL;
                LEFT NOBORDER
        /*****/
        oBtn1:nId := IDOK                
                       /*****/
        @ 68,67 BTNBMP oBtn2 PROMPT "&Cancel" ACTION ( lNoEsc := .T. , lSelecc:=.F. , oDlg:End()) OF oDlg SIZE 48,14 PIXEL;
                LEFT NOBORDER
        /*****/
        oBtn2:nId := IDCANCEL        

      ACTIVATE DIALOG oDlg CENTERED VALID lNoEsc
      if lSelecc
         MsgInfo(nOpr)     // <=== *** THIS MUST BE PROCESSED IF, AND ONLY IF, WE CLICK ON THE "SELECT" BUTTON. *** //
      endif
    Return(NIL)


and to modify the callclick function in the control class

Code: Select all  Expand view  RUN
Static function CallClick( nKey, aControls, Self )

   local n, cPrompt, nAt, oControl

   for n = 1 to Len( aControls )
      oControl = aControls[ n ]
      if oControl:Classname() == "TBTNBMP" .OR. oControl:Classname() == "TRBTN"
        cPrompt := aControls[ n ]:cCaption
         nAt = At( "&", cPrompt )
         if nAt != 0
            if Upper( SubStr( cPrompt, nAt + 1, 1 ) ) == Upper( Chr( nKey ) ) .and. IsWindowEnabled( aControls[ n ]:hWnd )              
               IF oControl:Classname() == "TBTNBMP" .AND. (nKey == VK_F4 .and. GetKeyState( VK_MENU ))
                        n := AScan( aControls, { |o| o:nID == IDCANCEL } )
                        IF n > 0
                                SetFocus( aControls[ n ]:hWnd )
                                aControls[ n ]:Click()
                        endif
               ELSE
                        SetFocus( aControls[ n ]:hWnd )
                        aControls[ n ]:Click()
               ENDIF
               
               return 0 // msg processed
            endif
         endif
      endif
   next

return nil


regards
Massimo
User avatar
MaxP
 
Posts: 88
Joined: Thu Jul 12, 2007 2:02 pm

Re: Bug in TBTNBMP Class FWH 19.12 ?

Postby cnavarro » Mon Feb 17, 2020 9:48 am

Hi Massimo, please read my message yesterday
viewtopic.php?f=6&t=38498#p229748
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Bug in TBTNBMP Class FWH 19.12 ?

Postby nageswaragunupudi » Tue Feb 18, 2020 4:50 pm

This is the final fix:

Please locate this line in the METHOD SysKeyDown( nKey, nFlags ) in control.prg:
Code: Select all  Expand view  RUN

   if ::oWnd:oMenu == NIL
 


Modify this line as
Code: Select all  Expand view  RUN

   if ::oWnd:oMenu == NIL .and. nKey != VK_F4
 


No other changes are required in control.prg

This fix is available in the next version of FWH under release.

Note:
ALTERNATIVELY,
Please see this line in the static function CallClick( nKey, aControls, Self )
Code: Select all  Expand view  RUN

            if Upper( SubStr( cPrompt, nAt + 1, 1 ) ) == Upper( Chr( nKey ) ) .and. IsWindowEnabled( aControls[ n ]:hWnd )
 

This line can be changed as
Code: Select all  Expand view  RUN

            if Upper( SubStr( cPrompt, nAt + 1, 1 ) ) == Chr( nKey ) .and. IsWindowEnabled( aControls[ n ]:hWnd )
 

This change also works instead of the above.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Bug in TBTNBMP Class FWH 19.12 ?

Postby Cgallegoa » Tue Feb 18, 2020 7:24 pm

Nages and Cristobal, thanks a lot. You are the best :D

I'll be waiting for the new version.

Regards
Saludos,

Carlos Gallego

*** FWH-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 494
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Bug in TBTNBMP Class FWH 19.12 ?

Postby nageswaragunupudi » Wed Feb 19, 2020 3:34 pm

On further testing we noticed that the first fix posted above is not full-proof. It is the second fix that works as expected.

This is the revised function:
Code: Select all  Expand view  RUN

Static function CallClick( nKey, aControls, Self )

   local n, cPrompt, nAt, oControl, cKey

   if nKey >= VK_NUMPAD0 .and. nKey <= VK_NUMPAD9
      // seen as 0x60 and Asc( "a" ) to Asc( "i" )
      nKey  -= 0x30  // converted to Asc( "0" ) to Asc( "9" )
   endif

   cKey  := Chr( nKey )

   if IsUpper( cKey ) .or. IsDigit( cKey ) // 2020-02-19

      for n = 1 to Len( aControls )
         oControl = aControls[ n ]
         if oControl:Classname() == "TBTNBMP" .OR. oControl:Classname() == "TRBTN"
           cPrompt := aControls[ n ]:cCaption
            nAt = At( "&", cPrompt )
            if nAt != 0
               if Upper( SubStr( cPrompt, nAt + 1, 1 ) ) == cKey .and. IsWindowEnabled( aControls[ n ]:hWnd )
                  SetFocus( aControls[ n ]:hWnd )
                  aControls[ n ]:Click()
                  return 0 // msg processed
               endif
            endif
         endif
      next

   endif

return nil
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi and 93 guests