Enumeration Class Woe

So I have tried to search the forum for help and find that I’m perhaps not the only person that has struggled a bit with Enumerations. I have perhaps misunderstood scope of usage but if I may, let me explain what I am trying to do…

I have a class (clsDBConn) that I am developing that handles database connectivity and will allow the creation and management of multiple concurrent recordsets. I have an enumeration called ConnType in the class and it is populated with MySQL,SQLite,SQLServer. I have a property in the class called DatabaseType which is declared with a type of ConnType.

I want to be able to identify which database type the instance of the class is connecting to as there are some nuances between databases that I need to handle in code. There will be more entries in the Enumeration in due course, these 3 are for initial testing.

In my main code I instantiate the class as DBConn and I set some other properties like DBName, User Password etc. and I have a line of code which is:

DBConn.DatabaseType = DBConn.ConnType.MySQL

The IDE happily sees all of this and will allow tab to autocomplete

I get a compile time error:

Type “clsDBConn” has no member named MySQL
DBConn.DatabaseType = DBConn.ConnType.MySQL (MySQL on this line is highlighted in Yellow)

I had thought that perhaps the scope was not right so I created a new property as a test (DoIt) also declared as ConnType and tried to assign DBConn.DatabaseType with DoIt.MySQL but I get a similar error.

I do know that I can achieve what I want using constants and if I use the Enumeration within a Method, it also works fine so am I simply trying to get the class to do something that Xojo does not like which can only be picked up at compile time?

I also know that if I strip out this code and simply assume that the Database is MySQL, the code works and can pull back the recordsets with no problems. So my issue is with how I am attempting to use the Enumeration. Putting the Enumeration into a Module does not feel right as it is integral to this class.

Thanks in advance,

Mark

When using an enum that’s defined in a class use the class super rather than the instance of when using the enum values.

DBConn.DatabaseType = clsDBConn.ConnType.MySQL

See if that works :slight_smile:

I was going to reply, but Tim beat me to it. Do what he said.

Doh! (Slaps Forehead).

That worked perfectly, one of those cannae see the wood for the trees moments.

Thank you gents, one happy camper here :slight_smile:

Mark

[quote=399593:@Tim Parnell]When using an enum that’s defined in a class use the class super rather than the instance of when using the enum values.

DBConn.DatabaseType = clsDBConn.ConnType.MySQL

[/quote]
I’ve regularly asked myself why the enumeration won’t work from an instance… Instances also know their enumerations, after all.