Crazy question about objects

I doubt if it is possible to do the following in XOJO:

AnyPage.MyWebListBox.AddRow(“Col1”,“Col2”,“Col3”)

I want to be able to swap the name of the “MyWebListBox” object at runtime.

Is that possible?

You could make the first portion into a variable like this:

Var lb as WebListBox = AnyPage.MyWebListBox
lb.AddRow(“Col1”,“Col2”,“Col3”)

And then just change out lb

1 Like

The problem continued.

The AnyPage.MyWebListBox object hasn’t changed yet.

Taking your example, imagine I want to do something this way and have it work. I know this syntax doesn’t work. I’m just trying to see if there’s a way anywhere.

Var MyStringProperty As String = "AnyPage.MyWebListBox"

Var lb as WebListBox = MyStringProperty
lb.AddRow(“Col1”,“Col2”,“Col3”)

MyStringProperty = "AnyPage2.MyWebListBox2"

Var lb as WebListBox = MyStringProperty
lb.AddRow(“Col1”,“Col2”,“Col3”)

That’s a longer version of

Var lb as WebListBox = AnyPage.MyWebListBox
lb.AddRow(“Col1”,“Col2”,“Col3”)

Var lb as WebListBox = AnyPage2.MyWebListBox2
lb.AddRow(“Col1”,“Col2”,“Col3”)

True.

I supposed, in the example, it is possible to assign the object from a String. If you try to run it in XOJO, it should not work. The compiler expects a WebListBox giving it a String.

But broadly speaking, that’s what I want to do. Having a property on an object and using it to call that object that contains the String.

You can create a dictionary in the session object, the key is the “AnyPage.MyWebListBox” and the value the actual reference to AnyPage.MyWebListBox

You just have to add and remove the references when you add/remove the pages

I guess you just really want to use something keeping the selected one set on a property, and are working with your mind wired unnecessarily to “strings”, aren’t you?

Exactly
That’s what I’m looking for.

Using your own example adapted:

Property MyProperty As WebListBox


MyProperty  = AnyPage.MyWebListBox


Var lb as WebListBox = MyProperty
lb.AddRow(“Col1”,“Col2”,“Col3”)


MyProperty = AnyPage2.MyWebListBox2


Var lb as WebListBox = MyProperty
lb.AddRow(“Col1”,“Col2”,“Col3”)

That can be reduced to: (removing the unnecessary intermediate “lb”)

Property MyProperty As WebListBox

MyProperty  = AnyPage.MyWebListBox

MyProperty.AddRow(“Col1”,“Col2”,“Col3”)

MyProperty = AnyPage2.MyWebListBox2

MyProperty.AddRow(“Col1”,“Col2”,“Col3”)
1 Like

Thank you very much to all.

I will write a class with a WebListBox property and experiment with it.

:+1:t2:

Phases to solve the question:

  1. Create class.

  2. Create a property with WebListBox type on that class. Set it as private.
    Captura de Pantalla 2023-05-15 a la(s) 18.48.00

  3. Create a set method to link the extern object with our property in the same object class. Set it as public.
    Captura de Pantalla 2023-05-15 a la(s) 18.49.37

  4. Fill data in our Grid to create a new class method and codify. You can fire in the show event.
    Captura de Pantalla 2023-05-15 a la(s) 18.50.37

  5. Add the class to the web page.

  6. In the opening event, write the code:

Me.Set_Grid(MyWebListBox_In_WebPage)