-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmList.pas
60 lines (50 loc) · 1.21 KB
/
mList.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
unit mList;
interface
uses
Classes, SysUtils, StrUtils, TypInfo, Math;
type
TmList = class(TList)
public
function Avg(ACampo : String) : Real;
function Max(ACampo : String) : Real;
function Min(ACampo : String) : Real;
function Sum(ACampo : String) : Real;
end;
implementation
function TmList.Avg(ACampo : String) : Real;
var
I : Integer;
begin
Result := 0;
for I := 0 to Count - 1 do
Result := Result + GetFloatProp(TObject(Items[I]), ACampo);
Result := IfThen(Count > 0, Result / Count, 0);
end;
function TmList.Max(ACampo : String) : Real;
var
I : Integer;
begin
Result := 0;
for I := 0 to Count - 1 do
if (I = 0) or (GetFloatProp(TObject(Items[I]), ACampo) > Result) then
Result := GetFloatProp(TObject(Items[I]), ACampo);
end;
function TmList.Min(ACampo : String) : Real;
var
I : Integer;
begin
Result := 0;
for I := 0 to Count - 1 do
if (I = 0) or (GetFloatProp(TObject(Items[I]), ACampo) < Result) then
Result := GetFloatProp(TObject(Items[I]), ACampo);
end;
function TmList.Sum(ACampo : String) : Real;
var
I : Integer;
begin
Result := 0;
for I := 0 to Count - 1 do
Result := Result + GetFloatProp(TObject(Items[I]), ACampo);
end;
//--
end.