Board index » delphi » Published property cannot be of type ARRAY

Published property cannot be of type ARRAY

Hello,

I'm converting a program from Delphi3 to Delphi6.
I'm getting following error message : "Published property 'Message' cannot
be of type ARRAY"

The error occurs on following line :
property Message2[index: integer]: TMsgString read GetMessage write
SetMessage;

Why does this compile in Delphi3 and not in Delphi6?
What can I do to avoid this error?

Tnx in advance

Bart

PS : class declaration is included

TMsgParameter = class(TIntegerParameter)
  private
    FMultiDisplay: Boolean;
    FDisplayTime: Integer;
    FMultiColor: Boolean;
    FTicks: Longint;
    FCurMsg: Integer;
    FMessages: array[0..Pred(SizeOf(Longint)*8)] of TMsgString;
    function  GetTrendLoggable: Boolean; override;
    procedure OnTimer;
    procedure SetMessage(Index: integer; value: TMsgString);
    function  GetMessage(Index: integer): TMsgString;
    procedure SetCurMsg(Value: integer);
    procedure SetMultiDisplay(Value: Boolean);
    procedure SetMultiColor(Value: Boolean);
  protected
     procedure AddProperties( L: TStringList); override;
  public
    constructor Create(AOwner: TComponent); override;
    function    GetText: string; override;
    procedure   Read(Sender: TObject);  override;
    procedure Print( Lines: TStrings); override;
    function SaveToOutLine( Outline: TOutline; ALevel: longint): Longint;
override;
    constructor LoadFromOutLine( AOwner: TComponent; Outline: TOutline;
ALevel: Longint); override;
  published
    property MultiDisplay: boolean read FMultiDisplay write FMultiDisplay
default False;
    property MultiColor: boolean read FMultiColor write SetMultiColor
default False;
    property DisplayTime: integer read FDisplayTime write FDisplayTime
default pcMsgParamDisplayTime;
    property Message[index: integer]: TMsgString read GetMessage write
SetMessage;
    property CurMsg: integer read FCurMsg write SetCurMsg default 0;
  end;

{***************************************************************************
***}
{* SetMessage
*}
{***************************************************************************
***}
procedure TMsgParameter.SetMessage;
begin
  if (Index >= Low(FMessages)) and (Index <= High(FMessages)) and
     (FMessages[Index] <> Value) then
  begin
    FMessages[Index] := Value;
    Invalidate;
  end;
end;

{***************************************************************************
***}
{* GetMessage
*}
{***************************************************************************
***}
function TMsgParameter.GetMessage;
begin
  if (Index >= Low(FMessages)) and (Index <= High(FMessages))
    then Result := FMessages[Index]
    else Result := ''
end;

 

Re:Published property cannot be of type ARRAY


This happened to me just the other day.

I fixed it by moving the array property from the
"published" section to a "public" section.

I admit I don't know all the differences between
"published" and "public" so this solution may
or may not work for you.

But it worked for me.

--
Thomas Bates

"NOTHING GREAT WAS EVER ACHIEVED WITHOUT ENTHUSIASM" - EMERSON
"Bart De Meester" <bart.demees...@pandora.be> wrote in message
news:5AcG8.88426$Ze.13420@afrodite.telenet-ops.be...

Quote
> Hello,

> I'm converting a program from Delphi3 to Delphi6.
> I'm getting following error message : "Published property 'Message' cannot
> be of type ARRAY"

> The error occurs on following line :
> property Message2[index: integer]: TMsgString read GetMessage write
> SetMessage;

> Why does this compile in Delphi3 and not in Delphi6?
> What can I do to avoid this error?

> Tnx in advance

> Bart

> PS : class declaration is included

> TMsgParameter = class(TIntegerParameter)
>   private
>     FMultiDisplay: Boolean;
>     FDisplayTime: Integer;
>     FMultiColor: Boolean;
>     FTicks: Longint;
>     FCurMsg: Integer;
>     FMessages: array[0..Pred(SizeOf(Longint)*8)] of TMsgString;
>     function  GetTrendLoggable: Boolean; override;
>     procedure OnTimer;
>     procedure SetMessage(Index: integer; value: TMsgString);
>     function  GetMessage(Index: integer): TMsgString;
>     procedure SetCurMsg(Value: integer);
>     procedure SetMultiDisplay(Value: Boolean);
>     procedure SetMultiColor(Value: Boolean);
>   protected
>      procedure AddProperties( L: TStringList); override;
>   public
>     constructor Create(AOwner: TComponent); override;
>     function    GetText: string; override;
>     procedure   Read(Sender: TObject);  override;
>     procedure Print( Lines: TStrings); override;
>     function SaveToOutLine( Outline: TOutline; ALevel: longint): Longint;
> override;
>     constructor LoadFromOutLine( AOwner: TComponent; Outline: TOutline;
> ALevel: Longint); override;
>   published
>     property MultiDisplay: boolean read FMultiDisplay write FMultiDisplay
> default False;
>     property MultiColor: boolean read FMultiColor write SetMultiColor
> default False;
>     property DisplayTime: integer read FDisplayTime write FDisplayTime
> default pcMsgParamDisplayTime;
>     property Message[index: integer]: TMsgString read GetMessage write
> SetMessage;
>     property CurMsg: integer read FCurMsg write SetCurMsg default 0;
>   end;

> {***************************************************************************
> ***}
> {* SetMessage
> *}
> {***************************************************************************
> ***}
> procedure TMsgParameter.SetMessage;
> begin
>   if (Index >= Low(FMessages)) and (Index <= High(FMessages)) and
>      (FMessages[Index] <> Value) then
>   begin
>     FMessages[Index] := Value;
>     Invalidate;
>   end;
> end;

> {***************************************************************************
> ***}
> {* GetMessage
> *}
> {***************************************************************************
> ***}
> function TMsgParameter.GetMessage;
> begin
>   if (Index >= Low(FMessages)) and (Index <= High(FMessages))
>     then Result := FMessages[Index]
>     else Result := ''
> end;

Re:Published property cannot be of type ARRAY


Quote
"Thomas Bates" <thomas.ba...@shaw.ca> wrote in message news:InqL8.95941
> I admit I don't know all the differences between
> "published" and "public" so this solution may
> or may not work for you.

Unlike Public properties, Published ones are displayed in the object
inspector and are stored in the .dfm file.

Re:Published property cannot be of type ARRAY


Quote
"Bruce Roberts" <b...@bounceitattcanada.xnet> wrote in message

news:XRqL8.2501$H67.13585@tor-nn1.netcom.ca...

Quote

> "Thomas Bates" <thomas.ba...@shaw.ca> wrote in message news:InqL8.95941

> > I admit I don't know all the differences between
> > "published" and "public" so this solution may
> > or may not work for you.

> Unlike Public properties, Published ones are displayed in the object
> inspector and are stored in the .dfm file.

So I'm guessing that that's why array-type properties are not permitted?
Although it seems that Collection-type properties are, if I'm not mistaken
(i.e. FieldDefs in a DataSet).

--
Thomas Bates

Re:Published property cannot be of type ARRAY


Quote
Thomas Bates wrote in message ...
>"Bruce Roberts" <b...@bounceitattcanada.xnet> wrote in message
>news:XRqL8.2501$H67.13585@tor-nn1.netcom.ca...

>> "Thomas Bates" <thomas.ba...@shaw.ca> wrote in message news:InqL8.95941

>> > I admit I don't know all the differences between
>> > "published" and "public" so this solution may
>> > or may not work for you.

>> Unlike Public properties, Published ones are displayed in the object
>> inspector and are stored in the .dfm file.

>So I'm guessing that that's why array-type properties are not permitted?
>Although it seems that Collection-type properties are, if I'm not mistaken
>(i.e. FieldDefs in a DataSet).

Probably, yes. Collections aren't arrays, by the way. They were
invented rather specifically to manage properties that are lists
(collections) of objects in the Object Inspector.

It's too strong to say that published properties are and public
properties aren't stored in the .dfm file. That's the default,
but you can override it with the "stored" keyword.

Groetjes,
Maarten Wiltink

Re:Published property cannot be of type ARRAY


On Thu, 6 Jun 2002 20:45:42 +0200, "Maarten Wiltink"

Quote
<maar...@kittensandcats.net> wrote:
> It's too strong to say that published properties are and public
> properties aren't stored in the .dfm file. That's the default,
> but you can override it with the "stored" keyword.

The real difference is RTTI. If compiled in the $M+ state (like
TPersistent and all its derivates), published properties will be seen
by RTTI. RTTI is used to stream properties.

Other Threads