1 | unit UPersistentData;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, UPDClient, Generics.Collections;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TPDManagerItem = class
|
---|
10 | Name: string;
|
---|
11 | ClientClass: TPDClientClass;
|
---|
12 | end;
|
---|
13 |
|
---|
14 | TPDManagerItems = class(TObjectList<TPDManagerItem>)
|
---|
15 | end;
|
---|
16 |
|
---|
17 | { TPDManager }
|
---|
18 |
|
---|
19 | TPDManager = class(TComponent)
|
---|
20 | public
|
---|
21 | Items: TPDManagerItems;
|
---|
22 | procedure Register(ClientClass: TPDClientClass);
|
---|
23 | procedure LoadToStrings(Strings: TStrings);
|
---|
24 | constructor Create(AOwner: TComponent); override;
|
---|
25 | destructor Destroy; override;
|
---|
26 | end;
|
---|
27 |
|
---|
28 | var
|
---|
29 | DefaultManager: TPDManager;
|
---|
30 |
|
---|
31 | procedure Register;
|
---|
32 |
|
---|
33 |
|
---|
34 | implementation
|
---|
35 |
|
---|
36 | uses
|
---|
37 | UPDClientXMLRPC, UPDClientMemory, UPDClientMySQL, UPDClientRegistry,
|
---|
38 | UPDClientINI;
|
---|
39 |
|
---|
40 | procedure Register;
|
---|
41 | begin
|
---|
42 | RegisterComponents('PersistentData', [TPDManager, TPDClientXMLRPC, TPDClientMemory,
|
---|
43 | TPDClientMySQL, TPDClientRegistry, TPDClientINI]);
|
---|
44 | end;
|
---|
45 |
|
---|
46 | { TPDManager }
|
---|
47 |
|
---|
48 | procedure TPDManager.Register(ClientClass: TPDClientClass);
|
---|
49 | var
|
---|
50 | NewItem : TPDManagerItem;
|
---|
51 | TempClass: TPDClient;
|
---|
52 | begin
|
---|
53 | try
|
---|
54 | TempClass := ClientClass.Create(nil);
|
---|
55 | NewItem := TPDManagerItem.Create;
|
---|
56 | NewItem.Name := TempClass.BackendName;
|
---|
57 | NewItem.ClientClass := ClientClass;
|
---|
58 | Items.Add(NewItem);
|
---|
59 | finally
|
---|
60 | TempClass.Free;
|
---|
61 | end;
|
---|
62 | end;
|
---|
63 |
|
---|
64 | procedure TPDManager.LoadToStrings(Strings: TStrings);
|
---|
65 | var
|
---|
66 | I: Integer;
|
---|
67 | begin
|
---|
68 | try
|
---|
69 | Strings.BeginUpdate;
|
---|
70 | Strings.Clear;
|
---|
71 | for I := 0 to Items.Count - 1 do
|
---|
72 | Strings.AddObject(TPDManagerItem(Items[I]).Name, TObject(TPDManagerItem(Items[I]).ClientClass));
|
---|
73 | finally
|
---|
74 | Strings.EndUpdate;
|
---|
75 | end;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | constructor TPDManager.Create(AOwner: TComponent);
|
---|
79 | begin
|
---|
80 | inherited;
|
---|
81 | Items := TPDManagerItems.Create;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | destructor TPDManager.Destroy;
|
---|
85 | begin
|
---|
86 | FreeAndNil(Items);
|
---|
87 | inherited;
|
---|
88 | end;
|
---|
89 |
|
---|
90 |
|
---|
91 | initialization
|
---|
92 |
|
---|
93 | DefaultManager := TPDManager.Create(nil);
|
---|
94 | DefaultManager.Register(TPDClientINI);
|
---|
95 | DefaultManager.Register(TPDClientRegistry);
|
---|
96 | DefaultManager.Register(TPDClientMemory);
|
---|
97 | DefaultManager.Register(TPDClientXMLRPC);
|
---|
98 | DefaultManager.Register(TPDClientMySQL);
|
---|
99 |
|
---|
100 | finalization
|
---|
101 |
|
---|
102 | FreeAndNil(DefaultManager);
|
---|
103 |
|
---|
104 | end.
|
---|
105 |
|
---|