Property in Module isn't seen on other windows

So the window has not been shown by this point.
Or it has been closed rather than hidden.

try turning the
ActionAntagonistQuestions

variable into a computed property

In the GET method, do this:

if mActionAntagonistQuestions = nil then
mActionAntagonistQuestions = new WinAntagonistActionAntagonistQuestions
end if

return  mActionAntagonistQuestions
1 Like

No, this is not the Main Window. Next to the WinMain there are 12 separate windows and at this moment I am getting this same NilObjectException on every window.

Xojo tells me that it cannot assign a value to this property:

Module1.mActionAntagonistQuestions.Get, line 2
Cannot assign a value to this property
mActionAntagonistQuestions = new WinAntagonistActionAntagonistQuestions

You need to have a property to store the actual value, that’s what the m property is for. In a few style guides, the m prefix commonly means “private”.

To super simplify and illustrate, you’ll end up with something similar to this:

When you access ComputedProperty the Get function runs, and because the actual value is nil a new instance is created before the actual value mComputedProperty is returned.

Update: You can also get Xojo to do a lot of the legwork for you on any existing property by using the contextual menu.

2 Likes

You should have a computed property named ActionAntagonistQuestions but your screenshot shows that the computed property is named mActionAntagonistQuestions.

You can right-click ActionAntagonistQuestions and select “convert to computed property”
image
that way you end with your computed property (with some code in Get and Set) and the corresponding private ‘m’ property (mActionAntagonistQuestions)
image

You will just need to adjust the Get code.

Edit: I think Tim edited his post while I was taking the screenshots. So this information is the same as above.

Edit2:

The Opening event of those windows does not execute just by opening your project.

1 Like

As others have pointed out, you didnt

but instead created a new variable yourself, with the m
Delete your mActionAntagonistQuestions
and convert ActionAntagonistQuestions

1 Like

Thanks, I fixed this. I wasn’t sure yet what a Computed Property was, but now I understand what it is doing.

Thanks for the explanation, Tim, I was a little confused what the Computed Property was about but now it’s clear to me.

André,

when you reach case(s) like this, create a brand new project, and try to make it work (using smal named properties, windows names, etc.).

The simple fact of doing this, will allow you to resolve the trouble, fast. Once done, you only have to set the solution in the main project.

Same with new feature: implement it in a brand new project, once it works, you only have to add it into the main project.

This will takes a bit of time (probably less than waiting a good answer from here) and allow yopu to keep h-you hair in your head / your computer on your desktop (instead of sending it through the window) ;).

Now, you use the was to develop you prefer.

You create useful and meaningful names (for you), but how can people can help when they have to read code with so long names:


Var antagonistIsSmart As String = 
ActionAntagonistQuestions.CCAntagonistQuestionList3Applied.Text_AntagonistIsSmart.text
 //Here I created a variable to make the long path shorter.

Also, following advices is a good idea. For example:


Var sql As String
sql = "UPDATE Customer SET City='" + CityField.Text + "' WHERE PostalCode='" + PostalCodeField.Text + "'"
Try
 db.ExecuteSQL(sql)

This code comes from the Xojo documentation, ExecuteSQL

This allows you to use the sql string to be reported in System.DebugLog sql

You will be able to read the sql contents once you click in this icon (in the IDE):
image

This icon is located at the ide’s bottom right (bottom-center of the screen).

1 Like

Thanks for the advice, Emile. I was still not able to fix this problem, but I am going to let it rest for some weeks and work on other parts of the program. Maybe when I come back to it I have some fresh eyes and see what it going on.

Is your window set to ImplicitInstance? If so, you wouldn’t have to use that separate property and can rely on it being not nil without further initialization.

I am using DesktopWindows and they don’t have the Implicit Instance property.

Sure they have. It’s just the property was placed on the second tab now. And is not in the docs property overview.
Bild 16.09.22 um 15.54

aah, I didn’t know that. I read somewhere that this wasn’t very trustable to use and that it was taken out because of that. It was already enabled for all the windows.

If so, try to use the window directly instead of creating a new one. Implicit instance is reliable but can be tricky at times – especially when you find you need that window more than once.
In your case, I don’t see that limitation. You shouldn’t run into NOEs with it.

And now it works! Thanks.

Actually, after having entered all the code, now when I open a window with the button press, there is a new window opened for every text field on that window. And when I enter text in text field on that window, a new window is opened as well. I believe that this is one of the problems when using Implicit instance.

No, thats what happens if you use the NEW keyword on the window type.

if you have a window called frmBanana
And you say frmBanana.show, then the ONE AND ONLY banana window will appear.
But if your button contains code that says

Var myBanana as new frmBanana
myBanana.show

Then you will get multiple copies of the window.

Each method has it’s benefits and problems.
If you want one and only copy, always talk about frmBanana, and never do a new as

Ofcourse, I understand the banana problem, however in this case, clicking in a text field should not create a New Window, or in my case, 12 new windows (there are 12 text fields on this specific window. No “As New” used anywhere here.

update:
Ok, I understand now that a window with Implicit instance enabled is in fact always open although hidden, and when an object on a hidden window is being activated, that window will show. Good to know. I should in that case start to work with hide and show windows

Yes, absolutely. You can consider a window you design in the IDE being a custom window subclass. So whenever multiple windows of that same type are necessary, you can create a new instance with the New command. In that case it is often better to loop through the existing windows if you want to retrieve it instead of having a separate property for it.
The same is valid for a window with ImplicitInstance set to True, but additionally one instance of that window class will be created, having the same name as the class. This can lead to confusions, especially at is indeed better to hide the window instead of closing it. But in any case you encounter several instances of the same window there must be a new somewhere in your code or something similar leading to an instantiation.