Class and its scope

In a Module I define a Class (CDDClass) with some properties, its scope = Global
In the Action event of a Button I create an instance with

dim newCDD as new CDDClass

The Button is on a Panel of a Pagepanel in a Window
In the next Panel I want to use this newCDD object but it is not known…I cannot use it.

Do I miss something here?

You are creating a complete new reference to your class. You need to do instead

classnameFromModule = new CDDClass

Trixi

Could you elaborate? I do not understand?

What did you name your property in the module? You need to instantiate this and not dim a complete new variable.

Are you German or Dutch?

HTH

Trixi

I’m Dutch but this project is for a German company, in fact I travel to Frankfurt this afternoon to demo the rough sketches.

The name of the class is CDDClass and it has a lot of properties… it is defined in a module called Globals

Ah, then you will travel to where I’m now :slight_smile: I just wanted to know if we can switch to German.

The class has a name “xxx”, then your property in the module has a name “yyy”. You need to write

yyy = new xxx

Trixi

[quote=19096:@Alexander van der Linden]In a Module I define a Class (CDDClass) with some properties, its scope = Global
In the Action event of a Button I create an instance with

dim newCDD as new CDDClass

[/quote]
The problem is with the “Dim” statement. That creates a variable that is local to the Action event of the Button and not available anywhere else. You need to add a Property to the Window or the Module or the App and instantiate a New CDDClass into that property. Then it will be available in the next panel.

Yes! Learned something new.

Thanks Tim
Danke Trixi…

Still some problems. I have defined a Property to the window and instantiated a new CDDClass into it, just like Tim said.
The IDE gives me in the autocomplete all the properties. When I use one of the properties I get a ‘NilObjectException’…

I am sure I’m lacking some deeper understanding of Xojo classes, but I can’t get it to work right now…

Please post some code or make an example. Have you read the documentation?

if kauferButton.Value = True then newCDD.Type ="Kaufer" elseif verkauferButton.value = True then newCDD.Type = "Verkaufer" elseif dienstleistungButton.value = True then newCDD.Type = "Dienstleistung" end if

And the NOE occurs at newCDD.Type = “Kaufer”??? What does the debugger tell you about newCDD? Did you set it to Nil somewhere?

Yes[quote=19112:@Beatrix Willius]ago Beta Testers
And the NOE occurs at newCDD.Type = “Kaufer”??? What does the debugger tell you about newCDD? Did you set it to Nil somewhere?[/quote]
Yes. No… I double checked…

and where in your code is your “NEW” statement…

newCDD= = new CDDClass

That is the important piece. newCDD will be in the scope of the location where it is created.

If it is created in a button action event… it vanishes when that event completes
If it isi created in a Window… it is available to that window only (or via window1.newcdd) only while that window is in scope.
If it is created a global in a Module than it is avaliable across the application (once it has been instantiated of course)

Is everything working now or do you still need help? Do you want me to have a short look at your computer via Skype either today or tomorrow afternoon?

[quote=19136:@Dave S]and where in your code is your “NEW” statement…

newCDD= = new CDDClass

That is the important piece. newCDD will be in the scope of the location where it is created.

If it is created in a button action event… it vanishes when that event completes
If it isi created in a Window… it is available to that window only (or via window1.newcdd) only while that window is in scope.
If it is created a global in a Module than it is avaliable across the application (once it has been instantiated of course)[/quote]

OK, I have this class and its properties defined in a module called ‘Globals’. If I understand the function of a module correctly, then classes/properties/methods etc are available in every part of the application.

In the Open event of the window I instantiate this class with: dim newCDD as new CDDclass. So far, so good? Do I have to bind the class to a Window property also? Don’t see the point in this…[quote=19166:@Beatrix Willius]Is everything working now or do you still need help? Do you want me to have a short look at your computer via Skype either today or tomorrow afternoon?[/quote]

Hi Trixi,

just arrived in Frankfurt. I just posted the above lines. It’s still a problem.

Hi Alexander,

no! You need to say

newCDD as new CDDClass

NO DIM!!! With the dim you create TWO variables but you want only on.

HTH

Trixi

It’s too warm: newCCD = new CDDClass is the correct syntax.

Certainly hot here… I’ll try later on this evening. Thanks for your kind cooperation. It’s a bit confusing…