Browse Source

Libraries: add TBox type to UCommon

Herman Schoenfeld 7 years ago
parent
commit
82124eb6b1
1 changed files with 33 additions and 0 deletions
  1. 33 0
      src/libraries/sphere10/UCommon.pas

+ 33 - 0
src/libraries/sphere10/UCommon.pas

@@ -133,6 +133,19 @@ type
 
   {$ENDIF}
 
+  { TBox }
+
+  TBox<T> = class(TObject)
+    private
+      FValue : T;
+    public
+      Instances: Integer; static;
+      property Value : T read FValue write FValue;
+      class constructor Create;
+      constructor Create(const AValue : T); overload;
+      destructor Destroy; override;
+  end;
+
   { TDateTimeHelper }
 
   TDateTimeHelper = record helper for TDateTime
@@ -723,6 +736,26 @@ begin
   end;
 end;
 
+{ TBox }
+
+class constructor TBox<T>.Create;
+begin
+  Instances := 0;
+end;
+
+constructor TBox<T>.Create(const AValue: T);
+begin
+  Inherited Create;
+  Inc(Instances);
+  FValue := AValue;
+end;
+
+destructor TBox<T>.Destroy;
+begin
+  Inherited;
+  Dec(Instances);
+end;
+
 {%endregion}
 
 {%region Date/Time Support }