Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


TabControl won't dispose?


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-21-2008, 05:08 AM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 157
Default TabControl won't dispose?

Okay, now, don't do this to me.

I've got a form, onto which I place a TabControl; on the various tab pages, I place panels, labels, etc. Everything is created dynamically. When each control is created, I add the name of that control to an ArrayList on the form.

When the form closes, I read through the ArrayList, from bottom to top, and dispose of each control.

This all works very will *until* I get to the TabControl. Running within the IDE doesn't produce any errors, but compile (optimized) for the device, and the Control( name ).Dispose produced an Invalid Cast Exception error.

The error occurs when I try to dispose of the TabControl.

I also started checking the type of the control before disposal, and using Control( name, TabControl ).Dispose. Same problem.

I imagine that, instead of disposing of the tab control, I could just remove all of the tab pages and set the visible to false; but I'd rather dispose of it.

Anyone?


Gary

__________________
PC: Windows XP Pro SP3 / Basic4PPC v6.5
PPC: HTC 8925 (AT&T Tilt) / Windows Mobile 6
Reply With Quote
  #2 (permalink)  
Old 03-21-2008, 10:29 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,770
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

I don't see this problem I'm afraid. What error occurs when you use the qualified form of Control()?

ctrl = "tab"
Control("ctrl).Dispose
'Gets compiled buts throws a runtime Invalid Cast error


ctrl = "tab"
Control(ctrl, TabControl).Dispose
'Works fine at runtime

Quote:
I also started checking the type of the control before disposal, and using Control( name, TabControl ).Dispose. Same problem.
If you are checking using ControlType then look at what it returns with a msgbox, it is not what you may think. You need to check for "TabControl.TabControl" not just "TabControl"
Reply With Quote
  #3 (permalink)  
Old 03-21-2008, 10:50 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

Are you using the most updated ControlsEx.dll?
ControlsEx update
Reply With Quote
  #4 (permalink)  
Old 03-21-2008, 02:25 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 157
Default

I am using ControlsEX.dll version 1.0.2995.34468, created 10 March 2008 at 7:52 AM.

This is the actual code I'm using:

Code:
Sub formGeneric_Close

	c = arrayListGenericControls.Count
	
	For x = ( c - 1 ) To 0 Step -1
	
		cn = arrayListGenericControls.Item( x )
	
		If StrIndexOf( ControlType( cn ), "TabControl", 0 ) <> -1 Then

			Control( cn, TabControl ).Dispose

		Else
	
			Control( cn ).Dispose

		End If

		arrayListGenericControls.RemoveAt( x )

	Next

End Sub
(One of these days I'm going to learn to include my code in the first post of a thread.)

__________________
PC: Windows XP Pro SP3 / Basic4PPC v6.5
PPC: HTC 8925 (AT&T Tilt) / Windows Mobile 6

Last edited by willisgt : 03-21-2008 at 02:28 PM.
Reply With Quote
  #5 (permalink)  
Old 03-21-2008, 02:35 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,770
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

I think that you have missed the significance of this sentence I posted.
Quote:
Originally Posted by agraham View Post
If you are checking using ControlType then look at what it returns with a msgbox, it is not what you may think. You need to check for "TabControl.TabControl" not just "TabControl"
EDIT :- Actually I'm wrong. I can't immediately see why that doesn't work.

Last edited by agraham : 03-21-2008 at 02:57 PM.
Reply With Quote
  #6 (permalink)  
Old 03-21-2008, 03:05 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,770
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

I slightly simplified your code for testing and it works for me. Perhaps you have something else wrong - like a case-difference with the names in the ArrayList.
Code:
Sub Form2_Close
		cn = "tab"	' tab is the name of the TabControl
		If StrIndexOf( ControlType( cn ), "TabControl", 0 ) <> -1 Then
			Control( cn, TabControl ).Dispose
		Else	
			Control( cn ).Dispose
		End If
End Sub
Reply With Quote
  #7 (permalink)  
Old 03-21-2008, 03:44 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 157
Default

Andy, you get full credit for this fix...

Apparently, your suggestion of checking both type 'TabControl' and 'TabControl.TabControl' had actually fixed the problem. Thing is, I also have a scrollbar on this form. So when I tried to dispose of the scrollbar, I was producing yet another cast exception error - identical, but from a different source.

My apologies for the oversight - I should have realized that both TabControl and ScrollBar types would do this.

__________________
PC: Windows XP Pro SP3 / Basic4PPC v6.5
PPC: HTC 8925 (AT&T Tilt) / Windows Mobile 6
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
add progressbar in to tabControl thaidelphi Questions & Help Needed 1 09-05-2008 05:55 PM
VGA + TabControl Elrick Questions & Help Needed 10 04-16-2008 02:25 PM
using dispose gives error on PPC and not on PC tvrman Questions & Help Needed 2 10-05-2007 07:32 PM
ArrayList won't dispose? willisgt Questions & Help Needed 1 08-30-2007 08:56 PM
ArrayList Dispose Method RandomCoder Bug Reports 2 07-02-2007 01:57 PM


All times are GMT. The time now is 03:27 AM.


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