FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to retrieve the button
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
How to retrieve the button
Posted: Mon Jul 12, 2010 08:26 PM
How do can I insert a number of buttons to a WINDOW with a variable name.
I tried:

Code (fw): Select all Collapse
FOR I:=1 to 6
 @ 200,100  BUTTONBMP aBtn[I] OF oGrund  ACTION MsgInfo( ?)  ;
         PROMPT STR(I)  PIXEL  SIZE 50,50 ;
         MESSAGE "Abbruch"
         
aBtn[I]:lDrag := .t.
next


But how can I retrieve the button name when I click on the button.

Thanks in advance
Otto
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: How to retrieve the button
Posted: Mon Jul 12, 2010 08:34 PM

Otto,

You can pass the variable 'I' to the function that you call when pressing the button.
Then you know the button that you have pressed.

Regards,
Marc

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to retrieve the button
Posted: Mon Jul 12, 2010 09:20 PM

Thank you Marc.
I tried this but "I" remains in my case always 7.
Best regards,
Otto

Posts: 782
Joined: Wed Dec 19, 2007 07:50 AM
Re: How to retrieve the button
Posted: Mon Jul 12, 2010 11:03 PM
Dear Otto:
Otto wrote:How do can I insert a number of buttons to a WINDOW with a variable name.

Try: aBtn[ nBtn ]:cTitle()
Or: aBtn[ nBtn ]:cCaption

Best regards.

Manuel Mercado Gómez.
manuelmercado at prodigy dot net dot mx
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to retrieve the button
Posted: Tue Jul 13, 2010 12:36 AM
In case of BTNBMP, we can write ACTION MsgInfo( ::cCaption )
In case of BUTTON on BUTTONBAR we can write ACTION MsgInfo( oThis:cCaption )

This is because the BtnBmp class evaluates the bAction codeblock with the button object as paramter.

TButtonBmp and its parent class TButton do not pass any parameter while evaluating the bAction block.

It is desirable to modify the TButton class and change the line 176 ( version 10.6 ) as Eval( ::bAction, Self )

Then we can write ACTION {|oBtn| MsgInfo( oBtn:<anydata>)}

Without changing the FWH library you may:
Code (fw): Select all Collapse
FOR I:=1 to 6
 @ 200,100  BUTTONBMP aBtn[I] OF oGrund  ;
         PROMPT STR(I)  PIXEL  SIZE 50,50 ;
         MESSAGE "Abbruch"
         
         aBtn[I]:bAction := MyActionBlock( aBtn, i )
         aBtn[I]:lDrag := .t.
next

static function MyActionBlock( aBtn, i )
return { || MsgInfo( aBtn[i]:<anydata> )}

We can not write " ... ACTION MsgInfo( aBtn[i]:<data> ). By the time this codeblock is executed the value of i is 7.
The function MyActionBlock uses the concept of detached locals. The function uses the values of aBtn and i, at the time of calling the function, for preparing the codeblock and the values are local to this function and do not change.
This is the way to create codeblocks within loops.

ALTERNATIVELY:
Code (fw): Select all Collapse
FOR I:=1 to 6
 @ 200,100  BUTTONBMP aBtn[I] OF oGrund  ;
         PROMPT STR(I)  PIXEL  SIZE 50,50 ;
         MESSAGE "Abbruch"
         
         aBtn[I]:OnClick := { |o| MsgInfo( o:cCaption ) }
         aBtn[I]:lDrag := .t.
next

In addition to bAction, there is another little known data oBtn:OnClick. This can also be used.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion