How can I access an object in another class?

I have created an object from my class “Settings” inside class “App” and I stored data inside the properties of my newly created instance. Now I want to access my properties in another class called “Window1”.

App → Event handlers → Open:

Var obj As Settings
obj = New Settings

For Each article as Dictionary in allArticles()
  obj.title.Add(article.Value("title"))
  obj.link.Add(article.Value("link"))
  obj.desc.Add(article.Value("description"))
Next

Window1 → PushButton1 → Action event handler:
How??

In the action event handler of PushButton1, I need to have access to all properties that were stored in the object before. How can I do that?

I would be very thankful if someone can help me.

Xojo is amazing, by the way!

Kind regards,
Alex

If you’re declaring the variable within the event with the Var (or Dim) keyword then the variable ceases to exist when the event finishes. To have the variable persist, and to make it available from other parts of your app, you’ll need to turn it into a property of the app.

Insert a new property into the App class (e.g. SettingsObj As Settings) and then modify the App.Open event to refer to it instead of the local variable:

' in App.Open:
 SettingsObj = New Settings 

Then elsewhere in your app you can refer to the property as a property of the App class:

' in Pushbutton1.Action
 App.SettingsObject.Foobar = 1

Thank you, it worked!

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.