unit class_basics;

interface

uses Contnrs;


{$REGION 'КЛАСС "Cущность'}
type
  TRD_Something = class (TObject)
    private
      f_name: string;           //Имя
      f_description: string;    //описание

    public
      function Get_name: string;
      function Get_description: string;

      constructor Create ( in_name, in_desc: string); virtual;
      destructor Destroy; override;
  end;
{$ENDREGION 'КЛАСС "Cущность'}


{$REGION 'КЛАСС "Массив Сущностей"'}
type
  TRD_List = class (TObjectList)
    private
      current_item: TRD_Something;
    public
      function Find_by_name( in_object_name: string ): TRD_Something; overload;
      function Index_by_name( in_object_name: string ): integer;
      function Next_item: TRD_Something; overload;
      function Prev_item: TRD_Something; overload;
      function First_item: TRD_Something; overload;
      function Last_item: TRD_Something; overload;

end;
{$ENDREGION}

implementation

{ TRD_Something }

{$REGION 'КЛАСС "СУЩНОСТЬ" РЕАЛИЗАЦИЯ'}
constructor TRD_Something.Create(in_name, in_desc: string);
begin
  inherited Create;
Assert( ( in_name <> '' ),
        'Входное поле ИМЯ СУЩНОСТИ класса RDSomething пустое!'+'{01A9B53C-F9C2-4501-9C17-23C7B7A1C51D}');

  self.f_name := in_name;
  self.f_description := in_desc;
end;

destructor TRD_Something.Destroy;
begin
  self.f_name := '';
  self.f_description := '';
  inherited;
end;

function TRD_Something.Get_description: string;
begin
   result := self.f_description;
end;

function TRD_Something.Get_name: string;
begin
 Assert( ( self.f_name <> ''),
          'Поле ИМЯ СУЩНОСТИ класса RDSomething пустое!'+'{74FAF375-02FB-4916-972B-607F52A944C0}');
   result := self.f_name;
end;
{$ENDREGION}

{ TRD_List }

{$REGION 'КЛАСС "Массив Сущностей" РЕАЛИЗАЦИЯ'}
function TRD_List.Find_by_name( in_object_name: string): TRD_Something;
var i: integer;
begin
result := nil;
if ( in_object_name <> '' ) then
  begin
    for i := 0 to self.Count - 1 do
    begin
      if ( ( self[ i ] as TRD_Something ).Get_name = in_object_name ) then
      begin
        result := self[ i ] as TRD_Something;
      end;
    end;
  end;
end;

function TRD_List.First_item: TRD_Something;
begin
  result:=self.First;
end;

function TRD_List.Index_by_name(in_object_name: string): integer;
var i: integer;
begin
result := -1;
if ( in_object_name <> '' ) then
  begin
    for i := 0 to self.Count - 1 do
    begin
      if ( ( self[ i ] as TRD_Something ).Get_name = in_object_name ) then
      begin
        result := i;
      end;
    end;
  end;
end;

function TRD_List.Last_item: TRD_Something;
begin
  result := self.Last;
end;

function TRD_List.Next_item: TRD_Something;
begin
  result := self[ Index_by_name( self.current_item.Get_name ) ];
end;

function TRD_List.Prev_item: TRD_Something;
begin

end;

{$ENDREGION}



end.
