E2188 Published property '%s' cannot be of type %s (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi)

Published properties must be an ordinal type, Single, Double, Extended, Comp, a string type, a set type which fits in 32 bits, or a method pointer type. When any other property type is encountered in a published section, the compiler will remove the published attribute -$M+


(*$TYPEINFO ON*)
program Produce;

  type
    TitleArr = array [0..24] of char;
    NamePlate = class
    private
      titleStr : TitleArr;
    published
      property Title : TitleArr read titleStr write titleStr;
    end;

begin
end.

An error is induced because an array is not one of the data types which can be published.


(*$TYPEINFO ON*)
program Solve;

  type
    TitleArr = integer;
    NamePlate = class
      titleStr : TitleArr;
    published
      property Title : TitleArr read titleStr write titleStr;
    end;

begin
end.

Moving the property declaration out of the published section will avoid this error. Another alternative, as in this example, is to change the type of the property to be something that can actually be published.