-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathuCardReaderManager.pas
121 lines (99 loc) · 3.03 KB
/
uCardReaderManager.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
******************************************************
USB Disk Ejector
Copyright (c) 2006 - 2015 Bennyboy
Http://quickandeasysoftware.net
******************************************************
}
{
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
unit uCardReaderManager;
interface
uses
classes;
type
TCardReader = packed record
VendorID: string;
ProductID: string;
ProductRevision: string;
end;
TCardReaderManager = class
private
function GetCardReadersCount: integer;
public
CardReaders: array of TCardReader;
constructor Create();
destructor Destroy; override;
procedure ClearCardReaderList;
procedure DeleteCardReader(const Index: Cardinal);
function AddCardReader(VendorID, ProductID, ProductRevision: string): boolean;
property CardReadersCount: integer read GetCardReadersCount;
end;
implementation
{ TCardReaderManager }
function TCardReaderManager.AddCardReader(VendorID, ProductID,
ProductRevision: string): boolean;
var
i: integer;
begin
result := true;
//Check it doesnt already exist
for I := 0 to CardReadersCount - 1 do
begin
if (CardReaders[i].VendorID = VendorID) and
(CardReaders[i].ProductID = ProductID) and
(CardReaders[i].ProductRevision = ProductRevision) then
begin
result := false;
exit;
end;
end;
SetLength(CardReaders, length(CardReaders) + 1);
CardReaders[high(CardReaders)].VendorID := VendorID;
CardReaders[high(CardReaders)].ProductID := ProductID;
CardReaders[high(CardReaders)].ProductRevision := ProductRevision;
end;
procedure TCardReaderManager.ClearCardReaderList;
begin
SetLength(CardReaders, 0);
end;
constructor TCardReaderManager.Create;
begin
SetLength(CardReaders, 0);
end;
procedure TCardReaderManager.DeleteCardReader(const Index: Cardinal);
var
ALength: Cardinal;
TailElements: Cardinal;
begin
ALength := Length(CardReaders);
Assert(ALength > 0);
Assert(Index < ALength);
Finalize(CardReaders[Index]);
TailElements := ALength - Index;
if TailElements > 0 then
Move(CardReaders[Index + 1], CardReaders[Index], SizeOf(TCardReader) * TailElements);
Initialize(CardReaders[ALength - 1]);
SetLength(CardReaders, ALength - 1);
end;
destructor TCardReaderManager.Destroy;
begin
SetLength(CardReaders, 0);
inherited;
end;
function TCardReaderManager.GetCardReadersCount: integer;
begin
result:=Length(CardReaders);
end;
end.