[Gambas-user] Adressing a self-made object

Bruce bbruen at ...2308...
Thu Oct 24 14:36:27 CEST 2013


On Thu, 2013-10-24 at 14:07 +0200, Alain Baudrez wrote:
> Hello,
> 
> I have been trying to emulate the VB.NET listbox control with checkboxes. I
> use this code to create and display them in a scrollview:
> 
> [code]
> 
> ' Declare a  checkbox
> Private hCheckbox As CheckBox
> 
> ' Create instances ofthe checkbox and place them
> ' in the parent Scrollview called ScrollFunction
> '
> Private Sub FillScrollBox()
> 
>   Dim vPos As Integer = 1 ' Counter representing the nth item
> 
>   $rs = $db.Exec("SELECT *  FROM tblListFunctie")
> 
>   For Each $rs
>     hCheckbox = New CheckBox(ScrollFunction)
>     With hCheckbox
>       .x = 10
>       .y = (vPos - 1) * hCheckbox.Height + 5
>       .width = 150
>       .text = $rs!Function
>       .tag = $rs!ID
>     End With
>     Inc vPos
> 
>   Next
> End
> [/code]
> 
> All checkboxes are displayed in the ScrollView, but how do I address any of
> those checkboxes?
> 
> I need to be able to set/read the value of those checkboxes. I tried :
> 
>    hCheckbox = New CheckBox(ScrollFunction) AS "chkScroll" & vPos
> 
> but I cannot address the object chkScroll1
> 
>   chkScroll1.value = TRUE
>  returns an 'Unknown Identifier'
> 
> Moreover, I don't know how many checkboxes I created. Yes, I could keep
> track of the variable vPos and use that, but is there a generic way to loop
> through only the checkboxes in their parent, namely the Scrollview?
> 
> Any tips are welcome
> 
> A.J.

Several things leap to mind, but this bit...
I need to be able to set/read the value of those checkboxes. I tried :
> 
>    hCheckbox = New CheckBox(ScrollFunction) AS "chkScroll" & vPos
> 
> but I cannot address the object chkScroll1

reading MIGHT .. be solved using the Last construct, as in

  Consructor:
                hCheckbox = new CheckBox(<parent>) as "chkScroll"

  Handler:
        Public Sub chkScroll_Click()   'or Change or Whatever
        
                Dim x as Control
                
                x=Last
                
                x.something=buggeriseAroundHere(x.Value)
                
        End

writing MIGHT .. be handled via the Tag property (not not not sure ???
haven't ever tried it)

Other things that leap to mind are the Actions approach (refer to the
fine help) or there is an example project that does something like
this.. somewhere.. "Calculator" perhaps? ( I am very tired.)

hth
Bruce






More information about the User mailing list