How to retrieve the button

How to retrieve the button

Postby Otto » Mon Jul 12, 2010 8:26 pm

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

Code: Select all  Expand view
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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to retrieve the button

Postby Marc Vanzegbroeck » Mon Jul 12, 2010 8: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: How to retrieve the button

Postby Otto » Mon Jul 12, 2010 9:20 pm

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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to retrieve the button

Postby mmercado » 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
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: How to retrieve the button

Postby nageswaragunupudi » 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: Select all  Expand view
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: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10628
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests