dim Session as Session = Session

Theres a long thread on the Xojo forums about Color shouldnt be a reserved property name

It really isnt. This is JUST the IDE preventing you from using the name IN the IDE

It causes no confusion.

The title of this article was, at one time, a recommended way for figuring out the current session in a Web 1.0 app

The compiler has NO issue sorting out whats a variable, whats a data type, and whats a method call.

In the code from the title it knows that :

  1. the first session following the dim MUST be a variable name (it cannot be a method call, property, constant or data type in that position)
  2. the second dim following the AS MUST be a datatype. It cannot be a variable name or method call, or property or constant etc
  3. and the last session, following the =, cannot be a data type. So it MUST be either another variable name OR method call. Since this line is just not defining this variable it cant be a usage of itself and that leaves ONLY a method as a possibility.

The compiler gets it right.

And you can see that it does if you :

  • start a new desktop project
  • add a new class and name it Foo
  • add a shared method to Window1, named foo() that returns foo
  • now add a property to Window1 named foo as foo
  • the in Window1.Open simply put this one line of code
self.foo = Foo

self.foo refers, int this case, to the PROPERTY (since there is no method that could possible be called – there is not assigns version that might cause ambiguity)

The Foo after the = has to be either a variable or method; Xojo’s preference is to call the method before trying to use a property

Now, would I recommend using the name of an existing data type as a property ? In general no but there are cases where it makes perfect sense.

Suppose to have a class that represents a run of text that all has the same type. Its a consistent type face, size, italic, bold etc and one of those properties on such a thing could reasonably be “Color”.

Many have suggested calling it something else for clarity. But that might actually BE the most accurate name for it. For instance Xojo itself has such a data type but they use the name “textcolor”. Color would actually be a suitable name here.

Here’s a sample project that does exactly this and has NO issue

EDIT : You can even write as one line in 2020r2.1

dim color as Color = Color.RGB(230,198, 178)

No confusion arises compiling this line (there may be ancillary issues with other code but COLOR isn’t “reserved” to ONLY be a data type name.

One Reply to “dim Session as Session = Session”

Comments are closed.