From Xojo Documentation
Allows the class to handle dot notation references that are not class members.
Allows the class to handle dot notation references that are not class members and return a value.
Use Operator_Lookup to define a function that will be called if the called item cannot otherwise be found in the class.
Operator_Lookup overloads a class's lookup operator. The method's first parameter must be a String which will receive the name of the desired member. The method can have any combination of other parameters and can have any return type. The Operator_Lookup operator is called whenever you use the foo.bar syntax to look up a member of an object and the compiler can't find anything named "bar". Before it returns an Undefined Identifier error, the compiler will try to call a lookup operator and pass "bar" as the first parameter. Overloading works for the lookup operator just as it does for any other method.
|If you implement Operator_Lookup on a class, you will no longer get compilation errors if you, for example, inadvertently misspell a property name. Instead, the Operator_Lookup method is called at runtime and is passed the name of your incorrectly spelled property.|
Gets values entered as dot notation from a Dictionary and returns the value:
// MyClass.AnyName returns what is in
Function Operator_Lookup(name As String) As String
If ValueDict.HasKey(name) Then
If Name = "SquareLength" Then Return Self.x^2 + Self.y^2
When you write:
it will return the result of the calculation. However, you can also write:
and it will compile and run, returning zero. This can lead to difficult to track down errors.