|
-
Jun 30th, 2006, 03:29 AM
#1
Thread Starter
New Member
Dynamic controls on Pocket PC
Hi,
i'm developing an application for pocket pc.
In this application I have a number of screens that I build dynamically according to database records.
I have the following code:
VB Code:
' Global
' Controls for screen A
Private ar_pcbThemaButtons() As PictureBox
' Controls for screen B
Private ar_pnlSubThemaButtons() As Panel
Private ar_pcbSubThemaButtons() As PictureBox
Private ar_lblSubThemaButtons() As Label
' Controls for Screen C
Private ar_pnlObjektenButtons() As Panel
Private ar_pcbObjektenButtons() As PictureBox
Private ar_lblObjektenButtons() As Label
Private sub getScreenA()
ClearPreviousScreen()
...
ar_data = getFromDB()
Dim i as integer
redim ar_pcbThemaButtons(ar_data.length - 1)
For i = 0 to ar_data.length - 1
ar_pcbThemaButtons(i) = new PictureBox
' Set Props for ThemaButton (Image, size, location)
.....
pnlButtonHolder.Controls.add(ar_pcbThemaButtons(i)
Next
End Sub
For screen B and C is that the same thing except that I use a
panel, picturebox and label for them.
Now between switching the screens I do a ClearPreviousScreen().
VB Code:
Private sub ClearPreviousScreen()
Dim oCtrl as Control
For each oCtrl in me.controls ' This is the place where it
goes wrong
oCtrl.visible = false
next
dim i as integer
if ScreenA then
for i = 0 to ar_pcbThemaButtons.length - 1
if not ar_pcbThemaButtons(i) is nothing then
ar_pcbThemaButtons(i).dispose() 'Remove the control
end if
next
end if
End Sub
So in the ClearPreviousScreen I dispose of the controls that I don't
need anymore.
This works for a while until the app exists without an error message. (At the point where I
start my loop through the me.Controls collection. )
Is my way of working incorrect?????
I can't seem to figure out what I'm doing wrong.
If I don't use the dispose on the array of controls the application doesn't exit.
But this results after a while in an out of memory error.
Could somebody help me out here?
Regards,
Steve
-
Jun 30th, 2006, 06:46 AM
#2
Thread Starter
New Member
Re: Dynamic controls on Pocket PC
I think I resolved my issue.
The exit happend on the disposing of the controls.
After searching the web and finding examples on dynamically UI generation I found some variations in disposing of controls.
My previous code was:
VB Code:
Private sub ClearPreviousScreen()
Dim oCtrl as Control
For each oCtrl in me.controls ' This is the place where it
goes wrong
oCtrl.visible = false
next
dim i as integer
if ScreenA then
for i = 0 to ar_pcbThemaButtons.length - 1
if not ar_pcbThemaButtons(i) is nothing then
ar_pcbThemaButtons(i).dispose() 'Remove the control
end if
next
end if
End Sub
Now I have altered it to:
VB Code:
Private sub ClearPreviousScreen()
Dim oCtrl as Control
For each oCtrl in Me.Controls
oCtrl.visible = false
Next
Dim i as integer
if ScreenA then
For i = oCt.Controls.Count - 1 To 0 Step -1
.... ' some checking
oCt.Controls.item(i).dispose()
Next
End If
End Sub
Apparantly the controls collection is getting confused on the removal of the controls.
Say I remove a control in the middle of the collection, the collection itself redefines itself with the new length and after I remove an other control that was previously on an other location in the collection, the program exits without any warning.
I have run memory check's on the application and my memory load is stable.
If there are better ways of doing such things please let me know.
Regards,
Steve
-
Jul 3rd, 2006, 08:23 PM
#3
Re: Dynamic controls on Pocket PC
Why do you create and dispose of the controls? Why not simply hide them?
An alternative would be to have three panels with the different controls on them, and swap them in and out of the view panel. I've posted more extensively about this idea on this forum, so I won't go into it here, but I would think it would be faster than what you are currently doing.
My usual boring signature: Nothing
 
-
Jul 4th, 2006, 01:58 AM
#4
Thread Starter
New Member
Re: Dynamic controls on Pocket PC
The purpose for this is for the memory consumption.
The screens are verry graphically.
Also the buttons for the screens are coming from a database.
Depending on one selection I get the needed subsection.
I also indicated 3 screens but there are more than 3 screens.
If I place them all in memory, this would be fast, there would be not enough remaining for a good use of the software.
I also have to play flash and wmv files in my software.
It is still on a pocket pc, so you have to dispose of the controls that are no longer necessary for the memory.
grtz
Steve
-
Jul 4th, 2006, 11:30 AM
#5
Re: Dynamic controls on Pocket PC
That's an issue. I have never gone over about a dozen screens, so I haven't run into any memory issues.
My usual boring signature: Nothing
 
-
Jul 5th, 2006, 01:54 AM
#6
Thread Starter
New Member
Re: Dynamic controls on Pocket PC
I had to find a balance between static and dynamic controls.
There where more problems with complete dynamic forms.
1. build a screen that is used as background where u use the onPaint and click event of the form
2. The form elements that are the same for a specific form make them invisible or of the screen
3. The elements that are derived from the database are the dynamically build ones
grtz
Steve
PS: I have about 17 screens
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|