Bug in TBTNBMP Class FWH 19.12 ?

Post Reply
Cgallegoa
Posts: 335
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador
Contact:

Bug in TBTNBMP Class FWH 19.12 ?

Post by Cgallegoa »

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

#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-20.07, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Bug in TBTNBMP Class FWH 19.12 ?

Post by nageswaragunupudi »

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
Cgallegoa
Posts: 335
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador
Contact:

Re: Bug in TBTNBMP Class FWH 19.12 ?

Post by Cgallegoa »

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 _ A. Martinez in 2009, and still not solved !

http://forums.fivetechsupport.com/viewt ... acelerador

Regards,
Saludos,

Carlos Gallego

*** FWH-20.07, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Bug in TBTNBMP Class FWH 19.12 ?

Post by nageswaragunupudi »

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

G. N. Rao.
Hyderabad, India
User avatar
MaxP
Posts: 85
Joined: Thu Jul 12, 2007 2:02 pm
Contact:

Re: Bug in TBTNBMP Class FWH 19.12 ?

Post by MaxP »

Hi Carlos,

I propose you to modify your source as below

Code: Select all

    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

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
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Bug in TBTNBMP Class FWH 19.12 ?

Post by cnavarro »

Hi Massimo, please read my message yesterday
http://forums.fivetechsupport.com/viewt ... 98#p229748
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Bug in TBTNBMP Class FWH 19.12 ?

Post by nageswaragunupudi »

This is the final fix:

Please locate this line in the METHOD SysKeyDown( nKey, nFlags ) in control.prg:

Code: Select all

   if ::oWnd:oMenu == NIL
 
Modify this line as

Code: Select all

   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

            if Upper( SubStr( cPrompt, nAt + 1, 1 ) ) == Upper( Chr( nKey ) ) .and. IsWindowEnabled( aControls[ n ]:hWnd )
 
This line can be changed as

Code: Select all

            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
Cgallegoa
Posts: 335
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador
Contact:

Re: Bug in TBTNBMP Class FWH 19.12 ?

Post by Cgallegoa »

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

I'll be waiting for the new version.

Regards
Saludos,

Carlos Gallego

*** FWH-20.07, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Bug in TBTNBMP Class FWH 19.12 ?

Post by nageswaragunupudi »

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

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
Post Reply