You have used a class instance variable in an array expression, but the class type has not declared a default array property.
program Produce; type Base = class end; var b : Base; procedure P; var ch : Char; begin ch := b[1]; end; begin end.
The example above elicits an error because 'Base' does not declare an array property, and 'b' is not an array itself.
program Solve; type Base = class function GetChar(i : Integer) : Char; property data[i : Integer] : Char read GetChar; default; end; var b : Base; function Base.GetChar(i : Integer) : Char; begin GetChar := 'A'; end; procedure P; var ch : Char; begin ch := b[1]; ch := b.data[1]; end; begin end.
When you have declared a default property for a class, you can use the class instance variable in array expression, as if the class instance variable itself were actually an array. Alternatively, you can use the name of the property as the actual array accessor.
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|