cwa
cwa

Reputation: 63

Declaring fixed size string properties in Delphi

How do I declare a fixed size string property in Delphi?

This is what I want to do, but I receive an error:

TMyObject = class(TObject)
private
  FName : string[20];
public
  property Name : string[20] read FName write FName;     //<-- error
end;

The compiler error reads: 'INDEX, READ, or WRITE clause expected, but '[' found'.

Upvotes: 4

Views: 992

Answers (1)

RRUZ
RRUZ

Reputation: 136391

try this

type
Str20=string[20];

TMyObject = class(TObject)
private
  FName : Str20;
public
  property Name : Str20 read FName write FName;     //<-- error
end;

Upvotes: 7

Related Questions