Array Question Regarding Custom User Controls

CharlesIPTI

Active Member
Licensed User
Longtime User
I cant tell where this error is being originated...

does B4A want the results member to be an initialized list or
am I having problems in the uiLogic method making the list of labels ?
 

Attachments

  • Array Error.zip
    27 KB · Views: 156

CharlesIPTI

Active Member
Licensed User
Longtime User
Please peek

OK I cleaned up quite a bit of errors mostly regarding accessing lists with Get(x) versus list(x)...


When I get to my method uiLogic.CreateBinControl
the parameter ordBinLablesList is a list of labels


The method returns my custom type "orderBinObj" which is made of a panel and a list of labels.

The calling method created a new instance of the object to recieve at the calling end ::

For x = 0 To orderBinCount
iBinNo = x +1
Dim binCrtl As orderBinObj
binCrtl = uiLogic.CreateBinControl(tmpLst, iBinNo)
'Can't be Zero
binCtrlObjLst.Add(binCrtl)
Next


in the method CreateBinControl I initialize a panel once and create new labels as it iterates.. i have gone so far as to abstract the panel and initialize one to assign to this object and return it.. that code is not in the attachment since it resulted in the same error.... on the second run through the method it always fails as if I haven't created a new panel but a new panel is created for every hit of the method, and 8 labels are created in this panel.. the monster then gets returned to the calling method ...... does anyone see my stupid mistake here I appreciate all insight thank you
 

Attachments

  • May 14th Test.zip
    31.5 KB · Views: 167
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip:
B4X:
Sub SetlblFontOrderBins(objPassed As Label) As Label
      Dim tmpLbl As Label
      tmpLbl = objPassed
      tmpLbl.TextColor = Colors.Black
      tmpLbl.TextSize = 20
      Return tmpLbl      
End Sub
Can be simplified:
B4X:
Sub SetlblFontOrderBins(objPassed As Label) As Label
      objPassed.TextColor = Colors.Black
      objPassed.TextSize = 20
      Return objPassed      
End Sub

If I understand correctly the problem is here:
B4X:
For x = 0 To orderBinCount
   iBinNo = x +1
   Dim binCrtl As orderBinObj
      binCrtl = uiLogic.CreateBinControl(tmpLst, iBinNo) ' Can't be Zero            
      binCtrlObjLst.Add(binCrtl)            
   Next
You are calling CreateBinControl multiple times with the same list. So the same views are added multiple times (which results in an error).
Are you using the debugger? Put a breakpoint in the line that causes the error. It happens on the second call to CreateBinControl.
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Thank you & A followup on structure

Appreciate the reminder on the unnecessary indirection with my tmpLbl versus directly using the passed in variable. I will avoid that kind of overkill now.

Regarding my error yes I'm using the debugger, and I noticed it hit on the second call to this method.

-- I couldn't tell what the view's parent was because of the lack of dept in the debugger or because of the absence of a watch window but I'm just whining again sorry ..

If I am just using the tmpLst parameter to
binCrtl = uiLogic.CreateBinControl(tmpLst) as a list of strings to create a new set of labels from ....would I still get the error if I change this source list to contain strings instead of label views?

Its just for reference to create views from and throw them into the panel. That list being supplied as a parameter doesn't need to be labels it could just be a list of strings to create labels from ...

Another thought was to just get the labels in the uiLogic.CreateBinControl method ??? Thanks again !!!
:sign0089:
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Remove View

The view gets "massaged" formatted processed if you will before assigning it to its final parent. During its construction it exists as a portion of a custom type... I had to remove it from this type that I am using as a holder for it before reassigning it to the parent Thanks you for all of your help.

Custom type { Panel with list of labels } lets call it <PanOfLbls>
In actual activity I use this custom type, with the panel now sized, and its list of labels all initialized to place them all into another custom type a list of the original custom type PanOfLbls. Lets call that <PanOfLblsList>

I iterate this list and place the controls onto a panel i have already sized for the activity and add that to the activity Phew !!!...
I simply remove them from the <PanOfLbls> Holder -- as I iterate through the list of them <PanOfLblsList> and re assign them to the real activity panel.

This may seem cumbersome or overkill to most but I needed some way to group these constructs as I format, structure and finally assign them to their final resting place in the activity .

Thanks again
 
Upvote 0
Top