Page 1 of 1

BTNBMP Question

PostPosted: Wed Oct 29, 2014 8:32 pm
by TimStone
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

Re: BTNBMP Question

PostPosted: Wed Oct 29, 2014 9:04 pm
by nageswaragunupudi
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.

Re: BTNBMP Question

PostPosted: Wed Oct 29, 2014 9:27 pm
by TimStone
Thank you.

That makes sense and it does work.

Tim