source: Generics/NativeGenerics/Generic/GenericRange.pas

Last change on this file was 496, checked in by chronos, 7 years ago
  • Modified: New native generics classes working under FPC 3.0 transformed from TemplateGenerics package.
File size: 694 bytes
Line 
1unit GenericRange;
2
3{$mode delphi}
4
5interface
6
7type
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
21implementation
22
23{ TGRange }
24
25procedure TGRange<T>.SetDistance(const AValue: T);
26begin
27 B := A + AValue;
28end;
29
30function TGRange<T>.GetDistance: T;
31begin
32 Result := B - A;
33end;
34
35procedure TGRange<T>.SetRange(NewA, NewB: T);
36begin
37 if NewA > NewB then begin
38 A := NewB;
39 B := NewA;
40 end else begin
41 A := NewA;
42 B := NewB;
43 end;
44end;
45
46end.
Note: See TracBrowser for help on using the repository browser.