Line | |
---|
1 | unit GenericRange;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | type
|
---|
8 |
|
---|
9 | TGRange<T> = class
|
---|
10 | private
|
---|
11 | procedure SetDistance(const AValue: T);
|
---|
12 | function GetDistance: T;
|
---|
13 | public
|
---|
14 | A: T;
|
---|
15 | B: T;
|
---|
16 | procedure SetRange(NewA, NewB: T);
|
---|
17 | property Distance: T read GetDistance write SetDistance;
|
---|
18 | end;
|
---|
19 |
|
---|
20 |
|
---|
21 | implementation
|
---|
22 |
|
---|
23 | { TGRange }
|
---|
24 |
|
---|
25 | procedure TGRange<T>.SetDistance(const AValue: T);
|
---|
26 | begin
|
---|
27 | B := A + AValue;
|
---|
28 | end;
|
---|
29 |
|
---|
30 | function TGRange<T>.GetDistance: T;
|
---|
31 | begin
|
---|
32 | Result := B - A;
|
---|
33 | end;
|
---|
34 |
|
---|
35 | procedure TGRange<T>.SetRange(NewA, NewB: T);
|
---|
36 | begin
|
---|
37 | if NewA > NewB then begin
|
---|
38 | A := NewB;
|
---|
39 | B := NewA;
|
---|
40 | end else begin
|
---|
41 | A := NewA;
|
---|
42 | B := NewB;
|
---|
43 | end;
|
---|
44 | end;
|
---|
45 |
|
---|
46 | end.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.