Results 1 to 6 of 6

Thread: Dynamic controls on Pocket PC

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Exclamation 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:
    1. ' Global
    2.     ' Controls for screen A
    3.     Private ar_pcbThemaButtons() As PictureBox
    4.  
    5.  
    6.     ' Controls for screen B
    7.     Private ar_pnlSubThemaButtons() As Panel
    8.     Private ar_pcbSubThemaButtons() As PictureBox
    9.     Private ar_lblSubThemaButtons() As Label
    10.  
    11.  
    12.     ' Controls for Screen C
    13.     Private ar_pnlObjektenButtons() As Panel
    14.     Private ar_pcbObjektenButtons() As PictureBox
    15.     Private ar_lblObjektenButtons() As Label
    16.  
    17.  
    18.     Private sub getScreenA()
    19.             ClearPreviousScreen()
    20.             ...
    21.             ar_data = getFromDB()
    22.  
    23.  
    24.             Dim i as integer
    25.             redim ar_pcbThemaButtons(ar_data.length - 1)
    26.             For i = 0 to ar_data.length - 1
    27.                    ar_pcbThemaButtons(i) = new PictureBox
    28.                    ' Set Props for ThemaButton (Image, size, location)
    29.                    .....
    30.                    pnlButtonHolder.Controls.add(ar_pcbThemaButtons(i)
    31.             Next
    32.     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:
    1. Private sub ClearPreviousScreen()
    2.              Dim oCtrl as Control
    3.              For each oCtrl in me.controls ' This is the place where it
    4. goes wrong
    5.                     oCtrl.visible = false
    6.              next
    7.  
    8.  
    9.              dim i as integer
    10.              if ScreenA then
    11.                    for i = 0 to ar_pcbThemaButtons.length - 1
    12.                           if not ar_pcbThemaButtons(i) is nothing then
    13.                                   ar_pcbThemaButtons(i).dispose()    'Remove the control
    14.                           end if
    15.                    next
    16.              end if
    17.      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

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    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:
    1. Private sub ClearPreviousScreen()
    2.              Dim oCtrl as Control
    3.              For each oCtrl in me.controls ' This is the place where it
    4. goes wrong
    5.                     oCtrl.visible = false
    6.              next
    7.  
    8.  
    9.              dim i as integer
    10.              if ScreenA then
    11.                    for i = 0 to ar_pcbThemaButtons.length - 1
    12.                           if not ar_pcbThemaButtons(i) is nothing then
    13.                                   ar_pcbThemaButtons(i).dispose()    'Remove the control
    14.                           end if
    15.                    next
    16.              end if
    17.      End Sub
    Now I have altered it to:

    VB Code:
    1. Private sub ClearPreviousScreen()
    2.              Dim oCtrl as Control
    3.              For each oCtrl in Me.Controls  
    4.                     oCtrl.visible = false
    5.              Next
    6.  
    7.              Dim i as integer
    8.              if ScreenA then
    9.                    For i = oCt.Controls.Count - 1 To 0 Step -1
    10.                           .... ' some checking
    11.                           oCt.Controls.item(i).dispose()
    12.                    Next
    13.             End If
    14.      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

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    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

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    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
  •  



Click Here to Expand Forum to Full Width