How to retrieve the button

Post Reply
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

How to retrieve the button

Post by Otto »

How do can I insert a number of buttons to a WINDOW with a variable name.
I tried:

Code: Select all

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: How to retrieve the button

Post by Marc Vanzegbroeck »

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
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: How to retrieve the button

Post by Otto »

Thank you Marc.
I tried this but "I" remains in my case always 7.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: How to retrieve the button

Post by mmercado »

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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to retrieve the button

Post by nageswaragunupudi »

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: Select all

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:<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: Select all

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