How to pass an array to a property?

Asked

Viewed 282 times

0

I am trying to pass an array of Strings and two Talignment arrays to three properties (Published). But I’m having the following mistake (which is the same for the three properties):

[dcc32 Error] uCad.pas(31): E2188 Published Property 'Columntitlename' cannot be of type ARRAY".

The code is below:

type
    TCad = class
    private
      FColumnTitleName: array of String;
      FColumnTitleAlign: array of TAlignment;
      FColumnAlign: array of TAlignment;
      function GetColumnAlign(index: Integer): TAlignment;
      function GetColumnTitleAlign(index: Integer): TAlignment;
      function GetColumnTitleName(index: Integer): String;
    public

    published
      property ColumnTitleName[index: Integer]: String read GetColumnTitleName;
      property ColumnTitleAlign[index: Integer]: TAlignment read GetColumnTitleAlign;
      property ColumnAlign[index: Integer]: TAlignment read GetColumnAlign;
  end;

implementation

function TCad.GetColumnAlign(index: Integer): TAlignment;
begin
  Result := FColumnAlign[index];
end;

function TCad.GetColumnTitleAlign(index: Integer): TAlignment;
begin
  Result := FColumnTitleAlign[index];
end;

function TCad.GetColumnTitleName(index: Integer): String;
begin
  Result := FColumnTitleName[index];
end;

end.

Does anyone know where I’m going wrong ?

Thank you.

1 answer

0

  • Hi Tiago. Thanks for the reply. I had seen this post you mentioned. Unfortunately there is no way to solve, because Delphi does not accept array in properties. I have resolved making properties public instead of Published. Hug.

  • Sorry, can you explain better the difference between your problem and that post? There you have array in properties, or not?

  • Is it because they are Published right? I’ve learned something hj :p

  • That’s right. From the time I moved the Property statements that were on Published to public, the above code worked. That is, you cannot place an array in a property in Object Inspector, but you can pass an array to a property by code. []s.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.