unit fmAssignDemo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, uMyObjs;

type
  TForm1 = class(TForm)
    btnCreateSource: TButton;
    btnCreateDest: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    GroupBox1: TGroupBox;
    eOuterName: TLabeledEdit;
    eOuterSize: TLabeledEdit;
    eInnerName: TLabeledEdit;
    eInnerSize: TLabeledEdit;
    GroupBox2: TGroupBox;
    dOuterName: TLabeledEdit;
    dOuterSize: TLabeledEdit;
    dInnerName: TLabeledEdit;
    dInnerSize: TLabeledEdit;
    GroupBox3: TGroupBox;
    eOuter1: TLabeledEdit;
    eInner1: TLabeledEdit;
    eOuter2: TLabeledEdit;
    eInner2: TLabeledEdit;
    procedure btnCreateSourceClick(Sender: TObject);
    procedure btnCreateDestClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
    outer1 : TOuter;
    outer2 : TOuter;
  public
    { Public declarations }
    procedure ShowOuter1;
    procedure ShowOuter2;
    procedure ShowObjectInfo(const outObj: TOuter; edtObj: TLabeledEdit);
    procedure ShowInnerObjectInfo(const innerObj: TInner; edtObj: TLabeledEdit);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnCreateSourceClick(Sender: TObject);
begin
  outer1 := TOuter.Create;
  outer1.SetName('Outer1');
  outer1.SetSize(100);
  outer1.GetInner.SetName('Inner1');
  outer1.GetInner.SetSize(111);
  ShowObjectInfo(outer1, eOuter1);
  ShowInnerObjectInfo(outer1.GetInner, eInner1);

  ShowOuter1;
end;

procedure TForm1.btnCreateDestClick(Sender: TObject);
begin
  outer2 := TOuter.Create;
  outer2.SetName('Outer2');
  outer2.SetSize(800);
  outer2.GetInner.SetName('Inner2');
  outer2.GetInner.SetSize(888);
  ShowObjectInfo(outer2, eOuter2);
  ShowInnerObjectInfo(outer2.GetInner, eInner2);

  ShowOuter2;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeAndNil(outer1);
  FreeAndNil(outer2);
end;

procedure TForm1.ShowObjectInfo(const outObj : TOuter; edtObj: TLabeledEdit);
begin
  edtObj.Text := Format('%p',[Pointer(outObj)]);
end;

procedure TForm1.ShowInnerObjectInfo(const innerObj: TInner;
  edtObj: TLabeledEdit);
begin
  edtObj.Text := Format('%p',[Pointer(innerObj)]);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  Outer2.Assign(Outer1);
  ShowOuter2;
  ShowInnerObjectInfo(outer2.GetInner, eInner2);
end;

procedure TForm1.ShowOuter1;
begin
  eOuterName.Text := outer1.GetName;
  eOuterSize.Text := IntToStr(outer1.GetSize);
  eInnerName.Text := outer1.GetInner.GetName;
  eInnerSize.Text := IntToStr(outer1.GetInner.GetSize);
end;

procedure TForm1.ShowOuter2;
begin
  dOuterName.Text := outer2.GetName;
  dOuterSize.Text := IntToStr(outer2.GetSize);
  dInnerName.Text := outer2.GetInner.GetName;
  dInnerSize.Text := IntToStr(outer2.GetInner.GetSize);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Outer2 := Outer1;
  ShowObjectInfo(outer2, eOuter2);
  ShowObjectInfo(outer2, eOuter2);
  ShowInnerObjectInfo(outer2.GetInner, eInner2);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  Outer2.Assign(Outer1);
  ShowOuter2;
  ShowInnerObjectInfo(outer2.GetInner, eInner2);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  Outer2.Assign(Outer1);
  ShowOuter2;
  ShowInnerObjectInfo(outer2.GetInner, eInner2);
end;

end.
