Re: getSelf( )

new topic     » goto parent     » topic index » view thread      » older message » newer message

Al Getz wrote:

> Hmmmm.  Funny i never had a problem with it and
> i've been running that code without a stack for
> months now.

I've verified that it's broken in the current release. Bother.

Run the code at the end of this message, and click the button. The first
messagebox reports one id, the second reports (after calling a getText,
which uses sendMessage) a different id.


> Can you offer a senerio to reproduce this problem?

Any time that sendMessage is called, getId() can be altered. sendMessage
immediately sends an event to the requested control/window. Since Win32Lib
has subclassed the default event handlers for all controls and windows,
either SubProc or WndProc will be invoked, depending on whether it was a
control or window that was sent the message.

The first thing that SubProc and WndProc do it attempt to identify the
Win32Lib handle of the control/window, and place the value on the stack. At
this point, you have a problem.


> What are the consequences of that problem if it does occur?

It's only an issue if you call getSelf() after a callback invokes
sendMessage. For example:

   procedure onSomeEvent( ... )
      integer self
      self = getSelf()
      sendMessage( ... )
   end procedure

won't cause any problems, because the correct value of self was retrieved
before SubProc/WndProc replaced it. If you instead wrote:

   procedure onSomeEvent( ... )
      integer self
      sendMessage( ... )
      self = getSelf()
   end procedure

then self will contain the wrong value, because it was called after
sendMessage.


> What unusual behaviour first made you realize this was a problem?

Someone reported a bug in an application which made use of getSelf(). The
app had two windows which mutually triggered paint events in the other one.

-- David Cuny



include win32lib.ew

constant
W  = create( Window, "getSelf() Bug", 0, Default, Default, 100, 140, 0 ),
B1 = create( PushButton, "Button 1", W, 10, 10, 80, 40, 0 ),
B2 = create( PushButton, "Button 2", W, 10, 50, 80, 40, 0 )

procedure click()
    object o
    -- should be the right value...
    o = message_box("self = " & sprintf( "%d", getSelf() ),"", MB_OK )
    o = getText( B2 )
    -- should be the wrong value...
    o = message_box("self = " & sprintf( "%d", getSelf() ),"", MB_OK )

end procedure
onClick[B1] = routine_id("click")

WinMain( W, Normal )

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu