Peter Pyshnyy
Peter Pyshnyy

Reputation: 53

How to use predefined variables in a class declaration

Is there a way to use a predefined variable inside a class or define it with a start value? My code:

TRoom = class(TObject)
   private
    pos: array[0..2] of integer;
    up: TRoom;
    right: TRoom;
    down: TRoom;
    left: TRoom;
--> freeSlots: array[0..3] of string = ('up','right','down','left'); <--
    content: string;
   end;

Upvotes: 2

Views: 255

Answers (1)

David Heffernan
David Heffernan

Reputation: 612854

Is there a way to use a predefined variable inside a class or define it with a start value?

No, you cannot declare initial values for instance member fields of a class. Classes are default intialized (i.e. to zero). If you want to assign an initial value then you should do so in a constructor.

Upvotes: 2

Related Questions