Shinya Okano avatar 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.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.