Dyn Array of Objects



Dynamic Array of Objects
Smart pascal source code
type TMyObj = class Field: Integer; constructor Create(i: Integer); end; type TMyObjects = array of TMyObj; constructor TMyObj.Create(i: Integer); begin Field := i * 2; end; { main.pas } var i: Integer; objs: TMyObjects; Begin objs := new TMyObj[3]; for i := 0 to Length(objs) - 1 do objs[i] := new TMyObj(i + 1); for i := Low(objs) to High(objs) do WriteLn(objs[i].Field); objs.Add(TMyObj.Create(10)); objs.Delete(1, 2); for i := Low(objs) to High(objs) do WriteLn(objs[i].Field); { <<< CONSOLE OUTPUTS >>> 2 4 6 2 20 } end;