BTNBMP Question

BTNBMP Question

Postby TimStone » Wed Oct 29, 2014 8:32 pm

I realize there are two threads going on the buttons, but this didn't necessarily fit in either so I'm trying a new one.

I moving a lot of existing FUNCTION code into classes, as METHODs to be far more efficient. In doing so, I'm seeing a consistent behavior. Please consider the following two sections of a METHOD. The ::invnum is a field in a database object which is opened within the class.

REDEFINE BTNBMP RESOURCE "HROK" ID 2101 OF oDpw3 TOOLTIP "Use part" PROMPT "Use";
ACTION ( retval := ::invnum, oDpw3:end() ) NOBORDER TRANSPARENT

REDEFINE XBROWSE oLpa ID 2100 OF oDpw3 ON DBLCLICK( retval := ::invnum, oDpw3:end() )

This is a lookup list. Note the ACTION and DBLCLICK code is identical. If I click on the Bitmap, the program stops working ( no clear error message ). If I double click on an item, it successfully returns the value to the calling program. Both of these sections are in the exact same method.

This is built with FWH 13.08, Harbour, and Microsoft Visual Studio 2013. If I have the same calls in a FUNCTION by the same name, it works. In a CLASS METHOD, however, the error occurs.

I'd love some thoughts on this.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: BTNBMP Question

Postby nageswaragunupudi » Wed Oct 29, 2014 9:04 pm

At the beginning of the METHOD creating the BTNBMP, please declare a local

Code: Select all  Expand view
local oSelf := Self

....
Then modify the BTNBMP's action clause
Instead of
Code: Select all  Expand view
ACTION ( retval := ::invnum, oDpw3:end() )

modify as
Code: Select all  Expand view
ACTION ( retval := oSelf:invnum, oDpw3:end() )


First please test this change and I am sure it will work,

You want to know the reason.
The way the command translate of BTNBMP is written
::invnum is translated by the preprocessor as Self:invnum. But this Self is the button object, not "OUR" object.

I too learnt these lessons the hard way years back. So I invariably declare a local in every method creating FW objets
local oSelf := Self
Whether necessary or not, I use oSelf:myvariable instead of ::myvairable in the ACTION clauses of any FW control. May be this is not necessary in all cases and I may be over-cautious. But this saves lot of time and headaches.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10317
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: BTNBMP Question

Postby TimStone » Wed Oct 29, 2014 9:27 pm

Thank you.

That makes sense and it does work.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 108 guests