Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Bug Reports
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Bug Reports Post about errors or bugs encountered.


Different behavior in desktop vs. device on AddEvent


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-09-2008, 02:26 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 154
Default Different behavior in desktop vs. device on AddEvent

Not sure if this actually constitutes a bug, but it's an odd (and somewhat annoying) behavior I've observed recently.

I've written a program that creates certain buttons dynamically (e.g., at runtime). I also add a click event to those buttons using AddEvent.

When I run this program on the desktop ( F5>Run), open the form, close the form, and open it again, the buttons now have *two* events assigned to them, and both events get raised, even if it's the same event.

So...

Code:
   AddButton ("Form1", "Button1", 20,20,60,60,"Click Me")
   AddEvent ("Button1", Click, "MySub")

   Sub MySub
            msgbox( Sender.Text )
   End Sub
would display the message box twice. I had to write a little routine to keep track of what events had been assigned to what controls, to avoid adding the same event to a control twice.

Okay, part II - if I compile the same program for either the desktop or the device, run it, open the same form, click on the same controls (buttons), the duplicate events don't get raised, no matter how many times I assign the event to the control. In this case, I am *not* checking beforehand to see if I've already added the event to the control... I just add it every time the control gets created. It works perfectly.

So why then, is the behavior different when run from inside B4PPC?

Is this a bug, or am I missing somwthing?


Gary
Reply With Quote
  #2 (permalink)  
Old 01-09-2008, 03:05 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,143
Default

This code doesn't reproduce your problem:
Code:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    Form1.Show 
    AddButton ("Form1", "Button1", 20,20,60,60,"Click Me")
    AddEvent ("Button1", Click, "MySub")
End Sub

Sub MySub
    Msgbox( Sender.Text )
End Sub
The message box always appear once.
Reply With Quote
  #3 (permalink)  
Old 01-10-2008, 04:37 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 154
Default

Erel, you're right, the code you posted does not exhibit the behavior I described.

The program I'm attaching, however, does. Run the executable; click Button1, and Form2 opens. Click the 'Click Me' button, and a mesagew box appears. Close Form2. Click Button1 again, and Form2 opens once again. Click the 'Click Me' button, and the message box appears, but only once.

Now run Basic4PPC and load the .sbp file. Run it (F5). Form1 opens. Click Button1. Form2 opens. Click the 'Click Me' button, and a message box appears. Close Form2. Click Button1 again, and Form2 reopens. Click the 'Click Me' button, and the message box appears twice in rapid succession.

At least, that's the behavior on my desktop.

BTW, I am using Basic4PPC 6.0 on a computer running Windows XP Pro.


Gary
Attached Files
File Type: zip test.zip (12.6 KB, 7 views)
Reply With Quote
  #4 (permalink)  
Old 01-10-2008, 05:36 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,704
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by willisgt View Post
At least, that's the behavior on my desktop
And on mine. It looks like Control("Button2").Dispose on the desktop isn't truly disposing it. It looks as though it still has an entry in an event table somewhere in B4PPC even though it is cleared from a control list and so doesn't error when added again. So when it is added back the second AddEvent adds a second event to the event table. Interestingly one would then think that closing Form2 and reopening would give three Message boxes - but sadly it doesn't
Reply With Quote
  #5 (permalink)  
Old 01-13-2008, 01:29 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,143
Default

It is a bug.
It will happen when you use AddEvent with the same name more than once.
As agraham wrote the event will fire twice no matter how many times AddEvent is used.
This bug doesn't affect optimized compiled executables.

It will be fixed in the next major update (not the soon to come update).
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Web browser for desktop and device agraham Additional Libraries 46 Today 09:56 AM
Editable Table - Device & Desktop Erel Code Samples & Tips 11 11-21-2008 09:01 AM
Device or Desktop DaveW Questions & Help Needed 2 11-07-2008 01:04 PM
Different behaviour DeskTop and Device HARRY Questions & Help Needed 2 02-22-2008 01:36 PM
Using rapi from desktop to copy file from device to desktop sunnyboyj Questions & Help Needed 9 02-08-2008 12:40 PM


All times are GMT. The time now is 10:51 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0