New topic: Odd Button Behavior
<http://forums.realsoftware.com/viewtopic.php?t=46449> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message JoeEvert Post subject: Odd Button BehaviorPosted: Sat Jan 05, 2013 12:44 pm Joined: Fri Nov 18, 2005 7:04 pm Posts: 104 I have a button that generates some data that is rather time consuming (10-15 seconds). When the user clicks on the button I want to change the button text to indicate the report is running (I also have a progress bar on the window). Right after I change the text I disable the button, which I thought would prevent the user from clicking the button multiple times while the report was generating. As the code in the button runs and generates the data I can continue to click the button, even though I have disabled it. During this time the button does not grey out and indeed if I press the button several times while disabled but the code is running then process will start all over again when finished. It appears the button is not actually disabled when the code is executing in the action event Dim ButtonText As String = Me.Caption Me.Caption = "Generating Data" Me.Enabled = False For i as integer = 1 to 100000000 // do some lenghty process // if the button is clicked during this process // it will start all over, even though button has // been disabled above next // Restore button caption and re-enable Me.Caption = ButtonText Me.Enabled = True Is this normal behavior? This is RS2012R2 Top npalardy Post subject: Re: Odd Button BehaviorPosted: Sat Jan 05, 2013 1:25 pm Real Software Engineer Joined: Sat Dec 24, 2005 8:18 pm Posts: 7645 Location: Canada, Alberta, Near Red Deer Yes I'd actually try putting your long running code in a thread and do something like this in the action event of your button Make a new subclass of Thread called myThread Dim ButtonText As String = Me.Caption Me.Caption = "Generating Data" Me.Enabled = False dim t as new myThread( me , buttonText ) t.run Make mythread.constructor read as follows Constructor( pb as PushButton , captionToRestoreWith as string) mButtonToEnabledWhenDone = pb mButtonText = captionToRestoreWith add properties to myThread mButtonToEnabledWhenDone as pushButton mButtonText as string in the threads run event For i as integer = 1 to 100000000 // do some lenghty process // if the button is clicked during this process // it will start all over, even though button has // been disabled above next // Restore button caption and re-enable mButtonToEnabledWhenDone.Caption = mButtonText mButtonToEnabledWhenDone.Enabled = True _________________ My web site Great White Software RBLibrary.com REALbasic learning Top jakuno Post subject: Re: Odd Button BehaviorPosted: Sat Jan 05, 2013 1:29 pm Joined: Fri Aug 31, 2012 3:56 pm Posts: 50 Dim ButtonText As String = Me.Caption Me.Caption = "Generating Data" Me.Enabled = False self.Refresh // !!!!!! For i as integer = 1 to 100000000 // do some lenghty process // if the button is clicked during this process // it will start all over, even though button has // been disabled above next // Restore button caption and re-enable Me.Caption = ButtonText Me.Enabled = True Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
