source: ObjectBaseTypes/Level 1/UObjectInteger.pas

Last change on this file was 14, checked in by george, 15 years ago
  • Upraveno: Rozšíření sady tříd objektových typů.
File size: 2.3 KB
Line 
1unit UObjectInteger;
2
3interface
4
5uses
6 SysUtils, Classes, UObjectTypeBase, UObjectBoolean;
7
8type
9 TInteger = class(TInterfacedObject, IAssignable, IOrderable)
10 public
11 Value: Integer;
12 function Predecessor: IOrderable;
13 function Successor: IOrderable;
14 function Low: IOrderable;
15 function High: IOrderable;
16 procedure Assign(Source: TInterfacedObject);
17 function EqualTo(Operand: TInterfacedObject): TBoolean;
18 function HigherThen(Operand: IOrderable): TBoolean;
19 function LowerThan(Operand: IOrderable): TBoolean;
20 function Max(Operand1, Operand2: IOrderable): IOrderable;
21 function Min(Operand1, Operand2: IOrderable): IOrderable;
22 end;
23
24implementation
25
26uses
27 UObjectString;
28
29{ TInteger }
30
31procedure TInteger.Assign(Source: TInterfacedObject);
32begin
33 if Source is TInteger then Value := (Source as TInteger).Value
34 else if Source is TString then Value := StrToInt((Source as TString).Value)
35 else raise EConvertError.Create('');
36end;
37
38function TInteger.EqualTo(Operand: TInterfacedObject): TBoolean;
39begin
40 if Operand is TInteger then begin
41 Result := TBoolean.Create;
42 Result.Value := Value = TInteger(Operand).Value;
43 end else raise EInvalidCast.Create('Typecast error.');
44end;
45
46function TInteger.High: IOrderable;
47begin
48
49end;
50
51function TInteger.HigherThen(Operand: IOrderable): TBoolean;
52begin
53 if TInterfacedObject(Operand) is TInteger then begin
54 Result := TBoolean.Create;
55 Result.Value := Value > TInteger(Operand).Value;
56 end else raise EInvalidCast.Create('Typecast error.');
57end;
58
59function TInteger.Low: IOrderable;
60begin
61
62end;
63
64function TInteger.LowerThan(Operand: IOrderable): TBoolean;
65begin
66 if TInterfacedObject(Operand) is TInteger then begin
67 Result := TBoolean.Create;
68 Result.Value := Value < TInteger(Operand).Value;
69 end else raise EInvalidCast.Create('Typecast error.');
70end;
71
72function TInteger.Max(Operand1, Operand2: IOrderable): IOrderable;
73begin
74
75end;
76
77function TInteger.Min(Operand1, Operand2: IOrderable): IOrderable;
78begin
79
80end;
81
82function TInteger.Predecessor: IOrderable;
83begin
84 Result := TInteger.Create;
85 TInteger(Result).Value := Pred(Value);
86end;
87
88function TInteger.Successor: IOrderable;
89begin
90 Result := TInteger.Create;
91 TInteger(Result).Value := Succ(Value);
92end;
93
94end.
Note: See TracBrowser for help on using the repository browser.