You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

1

Tuesday, July 22nd 2014, 11:06pm

Is there a way to refer to a form at runtime?

If you have a form called frmTest, and maybe you have 2 controls, a listbox and a text box, lstTest and txtTest,


Can you refer to the form from the txtTest, at runtime? In other words, at runtime, if you type in the txtTest, this string:


frmTest.txtTest.Text


, is there a function that can read that string, and then return the value of Text, from txtTest?


Just trying to see if there are ways of querying the properties of the form, while the user is actually in the form.

spysonic

Trainee

  • "spysonic" is male

Posts: 88

Date of registration: Jul 11th 2014

About me: A beginner programmer.

Location: ...Jabaco Academy

Occupation: i have some but still not enough...

Hobbies: Jabaco

  • Send private message

2

Wednesday, July 23rd 2014, 4:13am

Hello..

dont know if this is what you mean.


Public Sub Text2_Change(ChangeType As ChangeType, ChangeEvt As DocumentEvent)
If Text2.Text = "form1.text1.text" Then: MsgBox Me.Text1.Text
End Sub


It display on the message box the string entered in text1 after typing "form1.text1.text" in text2"
sorry im a super beginner! :D

spysonic has attached the following image:
  • sample.jpg
.
.
Spare me, im new to Programming

This post has been edited 2 times, last edit by "spysonic" (Jul 23rd 2014, 4:22am)


jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

3

Wednesday, July 23rd 2014, 1:16pm

Hello..

dont know if this is what you mean.


Public Sub Text2_Change(ChangeType As ChangeType, ChangeEvt As DocumentEvent)
If Text2.Text = "form1.text1.text" Then: MsgBox Me.Text1.Text
End Sub


It display on the message box the string entered in text1 after typing "form1.text1.text" in text2"
sorry im a super beginner! :D


Thanks for trying Spy. But I was looking for a way to access the forms, by sort of compiling a component name string that is typed, while the application is running. It can't be hard-coded. It has to be typed in, during runtime.

So if a user types in a text box, "frmTest.Caption", I'd like to see if there's an internal function or method, that will be able to interpret that.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

4

Wednesday, July 23rd 2014, 2:48pm

But I was looking for a way to access the forms, by sort of compiling a component name string that is typed, while the application is running. It can't be hard-coded. It has to be typed in, during runtime.
Don't know, what you mean,
Do you mean something like
[ http://www.jabaco.org/board/1129-me-cont…k.html#post4192 ]
Where yoiu can access all created controls.

Or do you want to create your own control on runtime? :

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
Public Sub Form_Load()
   Dim b As New CommandButton
   b.Left = 50
   b.Top = 100
   b.Width = 200
   b.Height = 30
   b.Caption = "My Button"
   b.Enabled = True
   add(b)
   b.Visible = True
End Sub


Greatings
theuserbl


Edit:

Or do you mean something like this?`:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub Command1_Click()
  Dim clazz As java#lang#Class
  clazz = Command1.Parent.getClass
  Dim methods() As java#lang#reflect#Method
  methods = clazz.getMethods
  For i = 0 To Ubound(methods)
    Console.Print methods(i)
  Next i    
End Sub


Showing all existing methods.

You can also switch between

Jabaco Source

1
methods = clazz.getMethods
and

Jabaco Source

1
methods = clazz.getDeclaredMethods

This post has been edited 1 times, last edit by "theuserbl" (Jul 23rd 2014, 2:55pm)


Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

5

Wednesday, July 23rd 2014, 3:40pm

maybe he is talking about something like a 'Key Up Down Press Event' ...?

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

6

Wednesday, July 23rd 2014, 4:00pm

But I was looking for a way to access the forms, by sort of compiling a component name string that is typed, while the application is running. It can't be hard-coded. It has to be typed in, during runtime.
Don't know, what you mean,
Do you mean something like
[ http://www.jabaco.org/board/1129-me-cont…k.html#post4192 ]
Where yoiu can access all created controls.

Or do you want to create your own control on runtime? :

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
Public Sub Form_Load()
   Dim b As New CommandButton
   b.Left = 50
   b.Top = 100
   b.Width = 200
   b.Height = 30
   b.Caption = "My Button"
   b.Enabled = True
   add(b)
   b.Visible = True
End Sub


Greatings
theuserbl


Edit:

Or do you mean something like this?`:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub Command1_Click()
  Dim clazz As java#lang#Class
  clazz = Command1.Parent.getClass
  Dim methods() As java#lang#reflect#Method
  methods = clazz.getMethods
  For i = 0 To Ubound(methods)
    Console.Print methods(i)
  Next i    
End Sub


Showing all existing methods.

You can also switch between

Jabaco Source

1
methods = clazz.getMethods
and

Jabaco Source

1
methods = clazz.getDeclaredMethods

But I was looking for a way to access the forms, by sort of compiling a component name string that is typed, while the application is running. It can't be hard-coded. It has to be typed in, during runtime.
Don't know, what you mean,
Do you mean something like
[ http://www.jabaco.org/board/1129-me-cont…k.html#post4192 ]
Where yoiu can access all created controls.

Or do you want to create your own control on runtime? :

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
Public Sub Form_Load()
   Dim b As New CommandButton
   b.Left = 50
   b.Top = 100
   b.Width = 200
   b.Height = 30
   b.Caption = "My Button"
   b.Enabled = True
   add(b)
   b.Visible = True
End Sub


Greatings
theuserbl


Edit:

Or do you mean something like this?`:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub Command1_Click()
  Dim clazz As java#lang#Class
  clazz = Command1.Parent.getClass
  Dim methods() As java#lang#reflect#Method
  methods = clazz.getMethods
  For i = 0 To Ubound(methods)
    Console.Print methods(i)
  Next i    
End Sub


Showing all existing methods.

You can also switch between

Jabaco Source

1
methods = clazz.getMethods
and

Jabaco Source

1
methods = clazz.getDeclaredMethods



What I mean, is that an application with a form is already compiled, and is running. One of the components is a text box. In that text box, you would like to query attributes of the running form. Because you are the designer, you already happen to know the name of your form, .e.g 'frmTest'. So in the text box, which is a part of the form you are interested in, you want to be able to dynamically query properties of that form, during the running of that application.

It's sort of analagous to a query form, in a web app. Maybe there are some issues with your server, and you want some utility that is part of the web app, which allows you to query information about the server, or about the connections or resources that your running application is using.


theuserlb, the idea of creating your own control at runtime, is intriguing. However, your example is hard-coded. Is there a way to create a dynamic control, which was not specified in the actual code for the application, but which you create with commands from your textbox?



Here's the context -

I'm building a mini-ide, for testing Clojure expressions. In a standard Clojure repl, you can start building the forms interactively, view it, and query various properties of the form, while they are running. This isn't difficult, in a Clojure context, and it can be done in Jabaco, using Swing-related statements, in Clojure. However, in this case I would like to be able to query the Jabaco components of the actual application that is running, and if possible be able to change properties on the fly.

This is purely for exploration, to be able to see what is happening, in the universe of the running application.

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

7

Wednesday, July 23rd 2014, 4:12pm

have a look her at AbstractForm:

https://code.google.com/p/jabacoframewor…stractForm.jsrc

and this Function:

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
Private Function getParentContainer() As Container
   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") Or comp(i).getClass.getName.equals("javax.swing.JDesktopPane") Then
         boxComp = Cast(comp(i), Container)
      End If
   Next i

   getParentContainer = boxComp
End Function


this extracts the root containers for all components of your application.
It is used for Me.Controlls and the Anchor properties

This is a way to get a handle on things!
Not by their names used at designtime though, since the compiler strips those!!


Dani

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

8

Wednesday, July 23rd 2014, 5:06pm

have a look her at AbstractForm:

https://code.google.com/p/jabacoframewor…stractForm.jsrc

and this Function:

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
Private Function getParentContainer() As Container
   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") Or comp(i).getClass.getName.equals("javax.swing.JDesktopPane") Then
         boxComp = Cast(comp(i), Container)
      End If
   Next i

   getParentContainer = boxComp
End Function


this extracts the root containers for all components of your application.
It is used for Me.Controlls and the Anchor properties

This is a way to get a handle on things!
Not by their names used at designtime though, since the compiler strips those!!


Dani

Dani/theuserbl, this is the type of thing I'm looking for. Good to know that the actual design names are no longer available.

One more question - how would I find properties like the MousePointer (vbDefault) or Caption, for a parent form?

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

9

Wednesday, July 23rd 2014, 6:48pm

Quoted

Dani/theuserbl, this is the type of thing I'm looking for. Good to know that the actual design names are no longer available.

One more question - how would I find properties like the MousePointer (vbDefault) or Caption, for a parent form?


I already mentioned this link:
[ http://www.jabaco.org/board/1129-me-cont…k.html#post4192 ]

Every control have a SuperClass. That have itself a superclass, etc.
You can ask, in the program code, what control it is:

Jabaco Source

1
2
3
4
5
6
7
Public Sub Form_Load()
   For i = 0 To Me.Controls.size - 1
      If IsClass(Me.Controls.get(i), #CommandButton) Then
         Console.Print "A CommandButton: " & Me.Controls.get(i).ToString
      End If
   Next i
End Sub


Every CommandButton have a Caption, so you can cast it to CommandButton and call the Caption:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub Form_Load()
   For i = 0 To Me.Controls.size - 1
      If IsClass(Me.Controls.get(i), #CommandButton) Then
         Dim myCont As VB#CommandButton
         myCont = Cast(Me.Controls.get(i), VB#CommandButton)
         myCont.Caption = "New Text for the buttons"
      End If
   Next i
End Sub


Every Jabaco-Control is based on the interface VB#IJabacoControl.
So, every Jabaco-Control have a Width-Property.
And you can give every Jabaco-control, the same width:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub Form_Load()
   For i = 0 To Me.Controls.size - 1
      If IsClass(Me.Controls.get(i), #IJabacoControl) Then
         Dim myCont As VB#IJabacoControl
         myCont = Cast(Me.Controls.get(i), VB#IJabacoControl)
         myCont.Width = 300
      End If
   Next i
End Sub


Greatings
theuserbl





Edit:

And here to see, which controls have a "Caption"-property:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
Public Sub Form_Load()
   For i = 0 To Me.Controls.size - 1
      Dim myClass As Class = Me.Controls.get(i).getClass
      Dim methods() As java#lang#reflect#Method
      methods = myClass.getMethods
      For k = 0 To Ubound(methods)
        If methods(k).getName.equalsIgnoreCase("$Caption") Then
           Console.Print myClass + "   " + methods(k)
        End If
      Next k    
   Next i
End Sub


Greatings
theuserbl

This post has been edited 2 times, last edit by "theuserbl" (Jul 23rd 2014, 7:06pm)


jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

10

Wednesday, July 23rd 2014, 10:30pm

Quoted

Dani/theuserbl, this is the type of thing I'm looking for. Good to know that the actual design names are no longer available.

One more question - how would I find properties like the MousePointer (vbDefault) or Caption, for a parent form?


I already mentioned this link:
[ http://www.jabaco.org/board/1129-me-cont…k.html#post4192 ]

Every control have a SuperClass. That have itself a superclass, etc.
You can ask, in the program code, what control it is:

Jabaco Source

1
2
3
4
5
6
7
Public Sub Form_Load()
   For i = 0 To Me.Controls.size - 1
      If IsClass(Me.Controls.get(i), #CommandButton) Then
         Console.Print "A CommandButton: " & Me.Controls.get(i).ToString
      End If
   Next i
End Sub


Every CommandButton have a Caption, so you can cast it to CommandButton and call the Caption:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub Form_Load()
   For i = 0 To Me.Controls.size - 1
      If IsClass(Me.Controls.get(i), #CommandButton) Then
         Dim myCont As VB#CommandButton
         myCont = Cast(Me.Controls.get(i), VB#CommandButton)
         myCont.Caption = "New Text for the buttons"
      End If
   Next i
End Sub


Every Jabaco-Control is based on the interface VB#IJabacoControl.
So, every Jabaco-Control have a Width-Property.
And you can give every Jabaco-control, the same width:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub Form_Load()
   For i = 0 To Me.Controls.size - 1
      If IsClass(Me.Controls.get(i), #IJabacoControl) Then
         Dim myCont As VB#IJabacoControl
         myCont = Cast(Me.Controls.get(i), VB#IJabacoControl)
         myCont.Width = 300
      End If
   Next i
End Sub


Greatings
theuserbl





Edit:

And here to see, which controls have a "Caption"-property:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
Public Sub Form_Load()
   For i = 0 To Me.Controls.size - 1
      Dim myClass As Class = Me.Controls.get(i).getClass
      Dim methods() As java#lang#reflect#Method
      methods = myClass.getMethods
      For k = 0 To Ubound(methods)
        If methods(k).getName.equalsIgnoreCase("$Caption") Then
           Console.Print myClass + "   " + methods(k)
        End If
      Next k    
   Next i
End Sub


Greatings
theuserbl

Thanks theuserbl,

The examples are still hard-coded in the Form_load event unfortunately, but I might be able use this. Will give it a try, thanks.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

11

Wednesday, July 23rd 2014, 10:46pm

The examples are still hard-coded in the Form_load event unfortunately, but I might be able use this. Will give it a try, thanks.


Possible this will help you:
[ http://www.oracle.com/technetwork/articl…on-1536171.html ]

Not all what you can do in Java is possible in Jabaco.
For example, if you must use "void", that don't exists in Jabaco.

Greatings
theuserbl

Rate this thread
WoltLab Burning Board