forked from idursun/delphipi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PackageList.pas
81 lines (71 loc) · 1.73 KB
/
PackageList.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{**
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
**}
unit PackageList;
interface
uses SysUtils, Classes, PackageInfo, Generics.Collections;
type
TPackageList = class(TList<TPackageInfo>)
private
public
constructor Create;
function IndexOf(const PackageName: String): Integer; overload;
procedure SortList;
end;
implementation
uses Generics.Defaults;
type
TPackageInfoComparer = class(TInterfacedObject, IComparer<TPackageInfo>)
function Compare(const Left, Right: TPackageInfo): Integer;
end;
{ TPackageList }
constructor TPackageList.Create;
begin
inherited Create(TPackageInfoComparer.Create);
//OwnsObjects := true;
end;
function TPackageList.IndexOf(const PackageName: String): Integer;
var
I: Integer;
begin
Result := -1;
for I := 0 to count - 1 do
begin
if UpperCase(Self[i].PackageName) = UpperCase(PackageName) then
exit(i);
end;
end;
procedure TPackageList.SortList;
var
tmp : TPackageInfo;
i,j: Integer;
packagename: string;
changed : boolean;
begin
changed := true;
while changed do
begin
changed := false;
for i := 0 to Count - 1 do
begin
tmp := Self[i];
for packagename in tmp.RequiredPackageList do
begin
j := indexOf(packagename);
if (j > i) then
begin
Self.Exchange(i,j);
changed := true;
end;
end;
end;
end;
end;
{ TPackageInfoComparer }
function TPackageInfoComparer.Compare(const Left, Right: TPackageInfo): Integer;
begin
Result := CompareStr( UpperCase(Left.PackageName), UpperCase(Right.PackageName) );
end;
end.