:Click() error when TButton is disabled

Post Reply
User avatar
Maurilio Viana
Posts: 252
Joined: Tue Oct 25, 2005 2:48 pm
Location: Garça/Garza/Heron City - Brazil
Contact:

:Click() error when TButton is disabled

Post by Maurilio Viana »

Antonio, I found a little bug in TButton class using bWhen clause and Click method:
If bWhen clause is invalid but I do oBtn:Click() the bAction referred to oBtn is executed, a little sample:

redefine button oBtn ... of oDlg action AnyAction()
oBtn:bWhen := {|| .F. }

oDlg:bKeyDown := {|k| if(k=VK_F9, oBtn:Click(),) } // F9 fire action

function AnyAction()
? "oBtn was clicked"
return( Nil )

To solve I did: (In TButton.prg)


METHOD Click() CLASS TButton
if ! ::lProcessing
if ::bWhen # Nil .and. ! eval( ::bWhen )
return( Nil )
endif
(...)

--------------

*** I don't tested if it occur in other button controls like TBtnBmp, etc.

Regards,
Maurilio
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Maurilio,

Thanks :)

This way seems a little better:

Code: Select all

   if ! ::lProcessing
   
      ::lProcessing = .t.
      
      if ::bWhen != nil .and. ! Eval( ::bWhen ) 
         ::lProcessing = .f.
         return nil 
      endif    
      ...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Maurilio Viana
Posts: 252
Joined: Tue Oct 25, 2005 2:48 pm
Location: Garça/Garza/Heron City - Brazil
Contact:

Post by Maurilio Viana »

Thanks, Antonio!

Regards,
Maurilio
Post Reply