unit uMyObjs;

interface

uses
  SysUtils, Classes, Controls, Graphics, ExtCtrls;

type
  TInner = class(TPersistent)
  private
    sInnerName : String;
    iInnerSize : Integer;
  public
    function GetName : String;
    function GetSize : Integer;
    procedure SetName(const sName : String);
    procedure SetSize(const iSize : Integer);
    procedure Assign(Source: TPersistent); override;
  end;

  TOuter = class(TPersistent)
  private
    sOuterName : String;
    iOuterSize : Integer;
    objInner : TInner;
  public
    Constructor Create;
    Destructor Destroy; override;
    function GetName : String;
    function GetSize : Integer;
    function GetInner : TInner;
    procedure SetName(const sName : String);
    procedure SetSize(const iSize : Integer);
    procedure Assign(Source: TPersistent); override;
  end;

implementation

{ TOuter }

procedure TOuter.Assign(Source: TPersistent);
var
  aSObj : TOuter;
begin
  aSObj := TOuter(sOurce);
  Self.SetName(aSObj.GetName);
  Self.SetSize(aSObj.GetSize);
//  Self.objInner := aSObj.objInner;
  Self.objInner.Assign(aSObj.GetInner);
end;

constructor TOuter.Create;
begin
  objInner := TInner.Create;
end;

destructor TOuter.Destroy;
begin
  if Assigned(objInner) then
    FreeAndNil(objInner);
  inherited;
end;

function TOuter.GetInner: TInner;
begin
  Result := objInner;
end;

function TOuter.GetName: String;
begin
  Result := sOuterName;
end;

function TOuter.GetSize: Integer;
begin
  Result := iOuterSize;
end;

procedure TOuter.SetName(const sName: String);
begin
  sOuterName := sName;
end;

procedure TOuter.SetSize(const iSize: Integer);
begin
  iOuterSize := iSize;
end;

{ TInner }
procedure TInner.Assign(Source: TPersistent);
begin
  Self.sInnerName := TInner(Source).GetName;
  Self.iInnerSize := TInner(Source).GetSize;
end;

function TInner.GetName: String;
begin
  Result := sInnerName;
end;

function TInner.GetSize: Integer;
begin
  Result := iInnerSize;
end;

procedure TInner.SetName(const sName: String);
begin
  sInnerName := sName;
end;

procedure TInner.SetSize(const iSize: Integer);
begin
  iInnerSize := iSize;
end;

end.
