New type system
This commit is contained in:
@@ -10,9 +10,19 @@ type
|
||||
TImplDataDecimalType = class(TInterfacedObject, IDataDecimalType)
|
||||
private
|
||||
FScale: Integer;
|
||||
strict private
|
||||
class var
|
||||
// Pre-cached instances for scales 0-18.
|
||||
FDecimalTypes: TArray<IDataDecimalType>;
|
||||
public
|
||||
constructor Create(const AScale: Integer);
|
||||
|
||||
class constructor CreateClass;
|
||||
class destructor DestroyClass;
|
||||
|
||||
// Returns a cached instance for the specified scale.
|
||||
class function GetInstance(const AScale: Integer): IDataDecimalType; static;
|
||||
|
||||
// IDataType
|
||||
function GetName: String;
|
||||
function GetKind: TDataKind;
|
||||
@@ -54,6 +64,28 @@ begin
|
||||
FScale := AScale;
|
||||
end;
|
||||
|
||||
class constructor TImplDataDecimalType.CreateClass;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
// Create and cache singleton instances for each supported scale.
|
||||
SetLength(FDecimalTypes, 19);
|
||||
for i := 0 to High(FDecimalTypes) do
|
||||
FDecimalTypes[i] := TImplDataDecimalType.Create(i);
|
||||
end;
|
||||
|
||||
class destructor TImplDataDecimalType.DestroyClass;
|
||||
begin
|
||||
FDecimalTypes := nil;
|
||||
end;
|
||||
|
||||
class function TImplDataDecimalType.GetInstance(const AScale: Integer): IDataDecimalType;
|
||||
begin
|
||||
if (AScale < 0) or (AScale > High(FDecimalTypes)) then
|
||||
raise EArgumentException.CreateFmt('Scale for decimal must be between 0 and %d.', [High(FDecimalTypes)]);
|
||||
Result := FDecimalTypes[AScale];
|
||||
end;
|
||||
|
||||
function TImplDataDecimalType.CreateValue(const AValue: Int64): IDataDecimalValue;
|
||||
begin
|
||||
Result := TDataDecimalValue.Create(AValue, Self);
|
||||
|
||||
Reference in New Issue
Block a user