Subject POSSIBLE FIX: pushbutton
From Gaetano D. <gaetanodd@hotmail.com>
Date Mon, 8 Mar 2021 11:59:45 +1000
Newsgroups dbase.getting-started

On 8/03/2021 9:11, edward racht wrote:
> Greetings,
>
> just a question.
>
> Would this be the same problem that plagues radiobuttons?
>
> The following thread is in 'programming' newsgroup 2/7/2021
>
> Here is a solution that worked recently.
>
> just for the record, I have finally solved this issue.
> After marc's solution with the  keyboard "{Tab}" which was working
> pretty fine, a post in this forum way back from 2005, where a user was
> facing the very same issue with getting focus only at the second
> click, see attached screen shot.
> The solution was as simple as good - instead of using the
> radiobutton's OnChange event, the *OnLeftMouseUp* event was employed.
> This has brought two other advantages to simplify my code: Now I can
> do without checking if the event was firing for the radioutton with
> its value set to true - 'on LeftMouseUp' the radiobutton's value must
> be TRUE.
> And OnLeftMouseUp fires just once, just for the radiobutton which was
> clicked, leaving the other radiobuttons in the group untouched. This
> helped me in other places as well to straighten the code a good deal.
>
> Perhaps this info helps somebody else ....
>
> Thanks to everybody here!
>
> Kind regards, Heinz
>
> see attachment onleftmouseup.png
>
if the issue was happening while clicking the button, this could be
worth exploring, but when clicking the button, it works fine in all
dBase versions. It's when the accelerator key is used that something
fires multiple times.

Here is something that seems to fix the issue. You can't control how
many times an event fires but you can control how many times a
sub-function runs. You might want to try this with a customer property
of the for so it gets released when the form closes. @Mervyn, any
thoughts on what to attach the counter to?

Try this

** END HEADER -- do not remove this line
//
// Generated on 08/03/2021
//
parameter bModal
local f
f = new ghor38Form()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class ghor38Form of FORM
   with (this)
      height = 16.0
      left = 77.5
      top = 0.0
      width = 40.0
      text = ""
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_onClick
      height = 1.0909
      left = 13.0
      top = 4.0
      width = 15.2857
      text = "Pu&shbutton1"
      toggle = true
        value=false
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      height = 1.0
      left = 11.0
      top = 8.0
      width = 8.0
      value = "Entryfield1"
   endwith


    function displayControlName()
        if _app.nCount>1 // counter was left at 2 with a double-fire,
reset it
            _app.nCount=null
        elseif type("_app.nCount")=="U" or _app.nCount=null
            ?form.activecontrol.name
            _app.nCount=1
        elseif _app.nCount=1
            _app.nCount++ // make it 2
        elseif _app.nCount=2
            _app.nCount++ // make it 3
        elseif _app.nCount=3
            // gotta reset it at some stage, hopefully it only fires 3
times
            _app.nCount=null
        endif
    return

   function PUSHBUTTON1_onClick()
            form.displayControlName()
        return
endclass