Commits

Shinya Okano committed b4f8771

delphiの継承,インターフェースについてサンプルコードを追記

Comments (0)

Files changed (2)

delphi/delphi_oop/Makefile

+all:
+	dcc32 delphi_oop.dpr

delphi/delphi_oop/delphi_oop.dpr

+program testoop;
+
+{$APPTYPE CONSOLE}
+
+uses
+  System.SysUtils
+  ;
+
+type
+  ISay = interface(IInterface)
+    procedure Say;
+  end;
+
+  TParent = class(TInterfacedObject, ISay)
+  private
+    FValue: Integer;
+  public
+    procedure Say; virtual;
+    property Value: Integer read FValue write FValue;
+  end;
+
+  TChild = class(TParent)
+  public
+    procedure Say; override;
+  end;
+
+procedure TParent.Say;
+begin
+  Writeln('Parent.Say: ' + IntToStr(FValue));
+end;
+
+procedure TChild.Say;
+begin
+  Writeln('Child.Say: ' + IntToStr(FValue));
+end;
+
+var
+  Obj1, Obj2: TParent;
+
+begin
+  Obj1 := TParent.Create;
+  Obj1.Value := 10;
+  Obj1.Say;
+  Obj2 := TChild.Create;
+  Obj2.Value := 20;
+  Obj2.Say;
+end.