Object scope / variable / property

Hello everybody,
I have finally decided to learn xojo. My programming background is nearly zero and so is my OOP know how.
In my app I created a class A that holds some methods and properties.
I would like to create an object from class A at the start of the application and the object should live as long as the application is running.
Tried to define a variable in the app open event

Dim myObject as new A

and as expected myObject is available with its methods, but outside the open event it is not.
On the other hand, creating a property at app level seems to work and app.myObject is available everywhere.

My questions:

  • how should I create an object that must be reachable from “everywhere” correctly?
  • what is the difference between variable and property?

As a side note: yes, I searched, but I did not found anything helpful (that I could understand).

Thanks in advance!
Thomas

Or make a property at the Window level

[quote=434909:@Thomas Zenker]Hello everybody,
I have finally decided to learn xojo. My programming background is nearly zero and so is my OOP know how.
In my app I created a class A that holds some methods and properties.
I would like to create an object from class A at the start of the application and the object should live as long as the application is running.
Tried to define a variable in the app open event

Dim myObject as new A

and as expected myObject is available with its methods, but outside the open event it is not.[/quote]

Well you’d expect that too. myObject is a local variable. Local, that is, to the open event handler. It dies when the handler completes. If you want it to be available elsewhere, create it as a property of a window, f’rinstance. You’d still need to initialise it of course.

A variable is a something that is "Dim"ed in a method or event. It is local to that context and not available elsewhere. A property is similar to a variable, but is defined as part of an object. (App is an object, as is Window1.) It may also be part of a Module. A variable is created by you explicitly in the Dim statement. A Property is created by the system as part of the creation of the object.

I hope that is more clear.

Going by your name and location, you are probably German-savvy. This is an unfinished work but maybe offers a bit of start assistance: https://xojoblog.wordpress.com/2016/07/18/ferienvorschlag-mal-eben-programmieren-lernen/

Thanks a lot to all of you!
Your explanations made it a bit clearer to me.

Ulrich, yes I know German and will take a look at your “holiday proposal” :slight_smile: