Go Up to Error and Warning Messages (Delphi)
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.
Note: If you have hints turned on, you will receive two warnings about the value assigned to 'ch' never being used.