How to use predefined variables in a class declaration

Viewed 141

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;
1 Answers

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.

Related