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.


Disposing Controls


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-18-2008, 02:47 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
Awards Showcase
Beta Tester 
Total Awards: 1
Default Disposing Controls

It was my understanding that if a Panel or Form was disposed then all controls belonging to that Panel/Form would also be disposed.
However my latest app has shown that this is not the case.
Is this a change with V6 or am I just mistaken, as it appears to be undocumented?

I'm now using the GetControls method to dispose of all controls on a panel prior to disposing the panel which is working, however I also have a few objects which are not disposed using this method.
Is there a way to determine what objects are present and then can I dispose them?

Thanks,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #2 (permalink)  
Old 02-18-2008, 03:22 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

Forms can't be disposed.
When you dispose a panel only the panel gets disposed.
You can use something like:
Code:
somearray() = GetControls("Panel1")
for i = 0 to ArrayLen(somearray())-1
 Control(somearray(i)).Dispose
next
This is not so elegant but it will work (to find if a specific control exists):
Code:
Sub ControlExist(crl)
ErrorLabel(ControlExistErr)
a = ControlType(crl)
return true
ControlExistErr:
return false
End Sub
Reply With Quote
  #3 (permalink)  
Old 02-18-2008, 03:29 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 157
Default

I have often used an ArrayList to store the names of all the controls I create dynamically. This works well if I just want to know if a control exists.

More recently, I've switched to using a table, as I can also store the name of the control's parent (form, panel, etc), type, and other stuff I might want to keep track of.

Naturally, it's a simple matter to add an item to an array list - or a row to a table - when a control is created, and to remove it when a control is disposed of.

Gary
__________________
PC: Windows XP Pro SP3 / Basic4PPC v6.5
PPC: HTC 8925 (AT&T Tilt) / Windows Mobile 6
Reply With Quote
  #4 (permalink)  
Old 02-18-2008, 03:30 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by Erel View Post
Forms can't be disposed.
Thanks Erel.
Although the help file states that Forms do indeed have a Dispose property.

I'm currently using a similar code to yours to dispose of the controls on a panel but what about Objects?
Can I use a method to determine what Objects are present on the panel and then dispose them?
Ideally I would like to create and dispose of the tree view, context menu's and SMS messages as and when required, although if not possible then I will add at the start of the program and leave in place.

Regards,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #5 (permalink)  
Old 02-19-2008, 07:22 AM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
Awards Showcase
Beta Tester 
Total Awards: 1
Default

From the lack of responses, do I take it that it's not possible to determine what objects are in use (other than keeping my own record in an array list) and that I can't dispose of them anyway?

Regards,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #6 (permalink)  
Old 02-19-2008, 07:41 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

GetControls("") will return all controls and objects.
You could dispose objects the same way you dispose other controls.
Reply With Quote
  #7 (permalink)  
Old 02-19-2008, 07:43 AM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I will double check the problem I was having and report back later (about to leave for work now ).
Thanks for the reply.

Regards,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #8 (permalink)  
Old 02-19-2008, 10:26 AM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I found my problem as demonstarted in my sample code attached (just add ControlsEx.Dll to the same dir)...

It appears that Objects do not belong to the panel/form they are applied to, niether do they belong to the main form.

Now that I know this, disposing them is not a problem, I'll just keep track of which ones I need to delete.
My original intention was just to pass a sub the panel name and have it automatically delete all controls associated with it, I'll just need to re-work this slightly.

Thanks for the assistance.

Regards,
RandomCoder
Attached Files
File Type: sbp ControlsExample.sbp (898 Bytes, 10 views)
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
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
Drag controls (name) to the IDE Mr_Gee Basic4ppc Wishlist 2 07-21-2008 09:35 PM
HOTSPOT controls WZSun Code Samples & Tips 23 05-30-2008 02:42 PM
COM controls lairdre Questions & Help Needed 3 02-28-2008 09:53 AM
Controls name PepSoft Questions & Help Needed 4 12-17-2007 03:49 PM
Tab Order for Controls BPak Questions & Help Needed 2 05-06-2007 06:58 AM


All times are GMT. The time now is 04:02 AM.


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