-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathMVCBr.ContainedModel.pas
69 lines (56 loc) · 1.36 KB
/
MVCBr.ContainedModel.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
unit MVCBr.ContainedModel;
interface
uses
System.Classes, System.Sysutils,
System.Generics.Collections,
System.ThreadSafe, MVCBr.Interf, MVCBr.Model;
type
TMVCBrContainedModelFactory<T: IModel> = class(TModelFactory)
private
FList: TThreadSafeInterfaceList<T>;
public
constructor Create; override;
destructor Destroy; override;
procedure Release; override;
function LockList: TList<T>; virtual;
procedure UnLockList; virtual;
property Default: TThreadSafeInterfaceList<T> read FList;
function Add( AModel:T ):Integer;
end;
implementation
{ TMVCBrContainedModel<T> }
function TMVCBrContainedModelFactory<T>.Add(AModel: T): Integer;
begin
result := FList.add(AModel);
end;
constructor TMVCBrContainedModelFactory<T>.Create;
begin
inherited;
FList := TThreadSafeInterfaceList<T>.Create;
end;
destructor TMVCBrContainedModelFactory<T>.Destroy;
begin
Release;
FList.free;
FList := nil;
inherited;
end;
function TMVCBrContainedModelFactory<T>.LockList: TList<T>;
begin
result := FList.LockList;
end;
procedure TMVCBrContainedModelFactory<T>.Release;
var i:integer;
begin
for I := FList.count-1 downto 0 do
begin
FList.items[i].release;
FList.items[i] := nil;
FList.delete(i);
end;
end;
procedure TMVCBrContainedModelFactory<T>.UnLockList;
begin
FList.UnLockList;
end;
end.