You are not logged in.

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

1

Sunday, February 2nd 2014, 8:12pm

Me.Controls - Collection

Hey there,

inspired by theuserbls' Anchor implementation I came up with a Form.Controls Property aproach.

In VB you can iterate through Me.Controls to determine each controls' Type.

Source code

1
2
3
4
5
6
7
8
' Visual Basic 6.0
Private Sub MyControls()
    For Each Control in Me.Controls
        If TypeOf Control Is CheckBox Then
            Control.Value = False
        End If
    Next
End Sub


You can do that with Jabaco as follows.

I did not check out dialogs yet and don't know if this is reliable!?

This is not fully compatible to VB but probably more powerful.

I would aprechiate feedback on this one!


Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Public Sub Form_Load()
'intended for the Jabaco framework
'in IDE add some controls and a ComboBox
'Note: for ComboBox and Slider the names are not being retrieved; why? They are recognized though!! 
   For i = 0 To Me.Controls.size - 1
      Debug.Print i & ". Control: " & Me.Controls.get(i).getClass
      Debug.Print i & ". Control: " & Me.Controls.get(i).toString
      If IsClass(Me.Controls.get(i), #JComboBox) Then
         Dim myCont As VB#ComboBox
         myCont = Cast(Me.Controls.get(i), VB#ComboBox)
         myCont.enabled = False
      End If
   Next i
End Sub

Public Property Get Controls() As java#util#ArrayList 
   On Error Resume Next
   Dim comp() As java#awt#Component
   comp = getParentComponents.getComponents()
   Controls = New java#util#ArrayList
   Dim i As Integer, v As Integer
   For i = Ubound(comp) To 0 Step -1
      Controls.add comp(i)
      If IsClass(comp(i), #PictureBox) Then
         Dim picCont As #PictureBox
         picCont = Cast(comp(i), #PictureBox)
         For v = 0 To picCont.getComponentCount() - 1
            Controls.add picCont.Parent.getComponent(v)
         Next v
      ElseIf Isclass(comp(i), #Frame)Then
         Dim fraCont As #Frame
         fraCont = Cast(comp(i), #Frame)
         For v = 0 To fraCont.getComponentCount() - 1
            Controls.add fraCont.Parent.getComponent(v)
         Next v
      End If
   Next i
End Property

Private Function getParentComponents() As Container ' Let the added component resize, If its Anchor wants it
   Dim comp() As java#awt#Component
   Dim i As Integer
   comp = Me.getComponents()
  
   Dim rootComp As Container
   For i = 0 To Ubound(comp)
      If comp(i).getClass.getName.equals("javax.swing.JRootPane") Then
         rootComp = Cast(comp(i), Container)
      End If
   Next i

   comp = rootComp.getComponents  
   Dim layerComp As Container
   For i = 0 To Ubound(comp)
      If comp(i).getClass.getName.equals("javax.swing.JLayeredPane") Then
         layerComp = Cast(comp(i), Container)
      End If
   Next i

   comp = layerComp.getComponents
   Dim panelComp As Container
   For i = 0 To Ubound(comp)
      If comp(i).getClass.getName.equals("javax.swing.JPanel") Then
         panelComp = Cast(comp(i), Container)
      End If
   Next i

   comp = panelComp.getComponents
   Dim boxComp As Container
   For i = 0 To Ubound(comp)
      If comp(i).getClass.getName.equals("VB.Form$PictureBox") Then
         boxComp = Cast(comp(i), Container)
      End If
   Next i

   getParentComponents = boxComp
End Function

Private Sub AnchorResize()
   Dim comp() As java#awt#Component
   Dim i As Integer
   comp = getParentComponents().getComponents
   For i = 0 To Ubound(comp)
      If IsClass(comp(i), VB#IJabacoControl) Then
         Dim myCont As VB#IJabacoControl
         myCont = Cast(comp(i) , VB#IJabacoControl)
         myCont.ResizeTrigger(Parent.getContentPane.getWidth, Parent.getContentPane.getHeight)    
      End If
   Next i
End Sub


For some reason for ComboBox and Slider Control names are not being retrieved. They are accessible though!
I don't know why.


Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

2

Monday, February 3rd 2014, 12:16am

Nice. :)

Quoted

For some reason for ComboBox and Slider Control names are not being retrieved. They are accessible though!
I don't know why.

Because toString() gives out, what is in the toString() function defined and not what the name of the object is. But the function have to output a good description, because that is, what is expected, if toString() is called.
For CommandButton it is this one:
[ http://code.google.com/p/jabacoframework…svn128&r=90#114 ]
and for ComboBox it is this one:
[ http://code.google.com/p/jabacoframework…vn128&r=116#244 ]

Or for example, you can create a new SDI-project with one button, and write

Jabaco Source

1
2
3
Public Sub Command1_Click()
   Debug.print Me
End Sub


This outputs for example

Source code

1
Form1[frame0,386,263,508x434,layout=java.awt.BorderLayout,title=Form,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,4,30,500x400,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]


But this default description is only done by the Java Runtime.
You can overwrite it with

Jabaco Source

1
2
3
4
5
6
7
Public Sub Command1_Click()
   Debug.print Me
End Sub

Public Function toString() As String
  toString = "I am the Form component"
End Function


Now it gives out

Quoted

I am the Form component

And in Jabaco it works like in Java. A "Debug.print Me" is the same like "Debug.print Me.toString()". And "Debug.Print Me.Controls.get(i).toString" is the same like "Debug.Print Me.Controls.get(i)"
And "Debug.Print Me.Controls.get(i).getClass" is the same like "Debug.Print Me.Controls.get(i).getClass.toString".

But you are right, that the toString()-output of the ComboBox and Slider Control are empty, are not ok. So it should be fixed, to find a better description for it.

Greatings
theuserbl

This post has been edited 1 times, last edit by "theuserbl" (Feb 3rd 2014, 12:45am)


Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Monday, February 3rd 2014, 9:27am

Hey there theuserbl,

I think my initial problem has solved itself!

Source code

1
2
For some reason for ComboBox and Slider Control names are not being retrieved. They are accessible though!
I don't know why.


Today

Jabaco Source

1
Me.Controls.get(i).getClass


is returning the expected values. Yesterday form some reason the Jabaco Debuger did not return values for the ComboBox and the slider!
This has happened to me before!
The toString value is representing the controls' value and in my example ComboBox did not have any value added!

So I guess my aproach works fine after all!

I will do somemore testing; for dialogs as well...

What about VB compatibility. Should we try to provide the same syntax?
It would make things a lot more complicated and restricted!!


Dani

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

4

Tuesday, February 4th 2014, 11:49am

Ok,

using the same for Dialogs is no problem!

From what I read about java#awt#Component there seems to be no way to retrieve a components name given at designtime after compilation.
Simply because it is only a reference for the programmer and removed at runtime!

Correct me if I am wrong here.

However, it is possible to uniquely identify a component within its lifecycle by its hashCode:

Jabaco Source

1
Debug.Print i & ". Control: " & Me.Controls.get(i).hashCode


I actually don't see why I would need it though.

The way I introduced...

Source code

1
Public Property Get Controls() As java#util#ArrayList


above we would be able to iterate over all controls of a form or dialog and their subcontainers to access their properties.

Should we add this to the Jabaco framework?


Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

5

Saturday, April 12th 2014, 1:40pm

Only want to mention, that there is an update to this subject:
[ http://www.jabaco.org/board/1129-me-cont…-framework.html ]

Greatings
theuserbl

Rate this thread
WoltLab Burning Board