Subject Re: Pushbuttons
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Mon, 7 Oct 2019 11:35:45 +0530
Newsgroups dbase.getting-started

On 06/10/2019 21:25, Mervyn Bick wrote:
> On 2019-10-06 2:56 PM, Akshat Kapoor wrote:
>>
>> Good Evening Mervyn,
>> The change you suggested did the trick but it has aroused my curiosity.
>>
>> form.additem.itemsave.onclick = form.modi_item
>>
>> The above line is working fine for the past many months. Then why not
>> in the above case.
>>
>> Because of Macro substitution?
>> or because of passing of parameters.
>
> That's a very good question.
>
> cmd = [form.main]+temp+[.onclick = push_dbfform::push_onclick]
> &cmd
>
> would write the following
>
>    form.main1.onClick = push_dbfform::push_onclick
>
> This would allow the form to open without a problem.  Clicking on the
> pushbutton would execute the function.  The trouble is that the function
> push_onClick as it's written requires a parameter which will cause an
> error.
>
> Rewriting push_onClick so that it get's its parameter from something in
> the pushbutton that was clicked is a possibility.  Perhaps something like
>
> function push_onClick()
>     action = 'sub_'+this.text
>     form.result.text = action
>     ......
>     return
>
> Or you could save the action to a user-defined property, say action, of
> the pushbutton when it is constructed.  Then you can access it from the
> pushbutton's event handler.
>
>
>
> function push_onClick()
>     action = this.action
>     form.result.text = action
>     ......
>     return
>
> By assigning a codeblock to the pushbutton's onClick event handler the
> parameter gets passed with a minimum of fuss.
>
> Twelve programmers, a dozen solutions.  If it works, it's not wrong. :-)

Thank You for the explanation Mervyn,
Yes extracting what to do from Pushbutton properties is also possible
We can easily obtain which control has focus

       if type('this.parent.activeControl') # 'U'
           if this.parent.activeControl.Name == "CANCELPUSHBUTTON"
              this.stopTrying := true
              return
           endif
       endif

The above code is from password.cc of DUFLP uses this way only.
But I will prefer my way as it reduces ambiguity. We could be adding egg
to Chicken fried Rice or Chicken Chowmein.

But the main reason I had asked this question was that I have been using
Macro substitution for code like

On Key label L form.add_onClick(45)

And I had faced considerable problems and had to opt in for

e_sales = new e_salesForm()

and then later in the form
On Key label L e_sales.add_onClick(45)

The key stroke and the corresponding parameter are stored in a Table. I
will now try the solution you have provided in this case also and revert
to form. notation rather than e_sales notation.

Will revert if have any problems in that direction.

Regards
Akshat