where is my enumeration ?

just stuck with something I don’t understand …

I have a window named WindowChooseTableAndField
in that window, an enumeration :

Public Enum eWindowMode Normal ForeignKey End Enum

a constructor method :

Public Sub Constructor(aDatabase as VNSDatabase, workingMode as eWindowMode = eWindowMode.Normal) ... End Sub

I call that window from another part of the app ( in the main project)

Dim m As WindowChooseTableAndField.eWindowMode m = WindowChooseTableAndField.eWindowMode.ForeignKey Dim wch As New WindowChooseTableAndField( myVNSDatabase, m) If wch<>Nil Then

and I get that compile error :

Type "WindowChooseTableAndField.WindowChooseTableAndField" has no member named "eWindowMode" m = WindowChooseTableAndField.eWindowMode.ForeignKey

where is my mistake ?
thanks.

You might need to declare the enum as a global (or protected) in a module in order to use it outside of the window itself.

Alternatively, you could make a class called something like “ChooseWindow”, set its super to “Window” and add your enum to that class.

Then you can change the super of your “WindowChooseTableAndField” window to “ChooseWindow” and you will be able to access the enum via the ChooseWindow class anywhere in your app.

That method is a bit more convoluted, but it’s another option if it makes more sense for your application structure. For example, you might have a “WindowChooseTableAndField” window as well as a “WindowChooseDatabase” window. They could both share the “ChooseWindow” super and utilize the same enumerations (as well as other properties and methods if you’d like).

that’s a possibility … thanks.
let’s wait for the official xojo team answer ?

It is never a good idea to define something in a window that will be accessed by another window or public method, as it requires that window to be active and in scope for those attributes to be available. While there are circumstances where this may be desired or required, this probably isn’t one of them.

Jean… if you are going to dismiss what is probably the correct answer in deference to a response from an Xojo engineer, why didn’t you ask them directly via Feedback or a directly addressed message.

The purpose of this forum is for the community to help individuals,… not a XOJO ENGINEERING answers

The answer to your question as Jared pointed out, is CHANGE THE SCOPE

It is a bit strange that you can’t access the enum from an instance of the window, however.
Even if it isn’t the correct way to handle the scope of the variable, I would think that something like this would still work.

dim w as new EnumWindow dim myEnum as EnumWindow.Type myEnum = w.Type.SomeType

Interesting

Dave, I just want to have the official reason why this don’t work as expected (by me)
there is some subtle thing about enumerations in a window, they are allowed typing by the IDE , but dont work as enum in modules.
I would like to know why, and I’m sure for the records that some future forum users will like to know that too.

[quote=355331:@Jean-Yves Pochez]just stuck with something I don’t understand …

I have a window named WindowChooseTableAndField
in that window, an enumeration :

Public Enum eWindowMode Normal ForeignKey End Enum

a constructor method :

Public Sub Constructor(aDatabase as VNSDatabase, workingMode as eWindowMode = eWindowMode.Normal) ... End Sub

I call that window from another part of the app ( in the main project)

Dim m As WindowChooseTableAndField.eWindowMode m = WindowChooseTableAndField.eWindowMode.ForeignKey Dim wch As New WindowChooseTableAndField( myVNSDatabase, m) If wch<>Nil Then

and I get that compile error :

Type "WindowChooseTableAndField.WindowChooseTableAndField" has no member named "eWindowMode" m = WindowChooseTableAndField.eWindowMode.ForeignKey

where is my mistake ?
thanks.[/quote]
I copied your code into an empty project and it works without issues.

Found the error: you have ImplicitInstance on.

but I new my window at the beginning ?

Try it.

damn… it works ! thanks Eli !
still would like to know what happened …

is it a bug or something “closed by design” ?

By design.

A Window you create in the IDE is a class in a module. When you have ImplicitInstance = True an access function in the module with the same name is created. Something like this:

[code]Module WindowChooseTableAndField

Public Window WindowChooseTableAndField

End Window

// Only created if ImplicitInstance = True
Private Property mTheImplicitInstance As WindowChooseTableAndField = Nil

// Only created if ImplicitInstance = True
Global Function WindowChooseTableAndField() As WindowChooseTableAndField
If Not mTheImplicitInstance Then
mTheImplicitInstance = New WindowChooseTableAndField()
End
Return mTheImplicitInstance
End

End[/code]

Now using WindowChooseTableAndField outside of the class itself is a s follows:
– ImplicitInstance = True: the function WindowChooseTableAndField is used, the class is unreachable (“hidden” by the function)
– ImplicitInstance = False: the class WindowChooseTableAndField used

At least that is my interpretation of what’s going on after a decade of programming RB/Xojo.

Probably one of the worst decisions somebody at RB did in the 90s.

you’ve better die in the night because you learn something every day … thanks once again.

You learn something new and depressing every day.

Its done this way because it is in fact the only way to make some things work

The enumeration of a window could be generated as member of the module containing the window instead of the window itself. Then this issue wouldn’t be one.

or generate a more explicit error message “turn off the implicit property of your window if you want this to work” …?

If we generate it as part of the module it would be in the wrong scope and present other issues