source: trunk/Packages/PersistentData/UPersistentData.pas

Last change on this file was 142, checked in by chronos, 2 years ago
File size: 2.0 KB
Line 
1unit UPersistentData;
2
3interface
4
5uses
6 Classes, SysUtils, UPDClient, Generics.Collections;
7
8type
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
28var
29 DefaultManager: TPDManager;
30
31procedure Register;
32
33
34implementation
35
36uses
37 UPDClientXMLRPC, UPDClientMemory, UPDClientMySQL, UPDClientRegistry,
38 UPDClientINI;
39
40procedure Register;
41begin
42 RegisterComponents('PersistentData', [TPDManager, TPDClientXMLRPC, TPDClientMemory,
43 TPDClientMySQL, TPDClientRegistry, TPDClientINI]);
44end;
45
46{ TPDManager }
47
48procedure TPDManager.Register(ClientClass: TPDClientClass);
49var
50 NewItem : TPDManagerItem;
51 TempClass: TPDClient;
52begin
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;
62end;
63
64procedure TPDManager.LoadToStrings(Strings: TStrings);
65var
66 I: Integer;
67begin
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;
76end;
77
78constructor TPDManager.Create(AOwner: TComponent);
79begin
80 inherited;
81 Items := TPDManagerItems.Create;
82end;
83
84destructor TPDManager.Destroy;
85begin
86 FreeAndNil(Items);
87 inherited;
88end;
89
90
91initialization
92
93DefaultManager := TPDManager.Create(nil);
94DefaultManager.Register(TPDClientINI);
95DefaultManager.Register(TPDClientRegistry);
96DefaultManager.Register(TPDClientMemory);
97DefaultManager.Register(TPDClientXMLRPC);
98DefaultManager.Register(TPDClientMySQL);
99
100finalization
101
102FreeAndNil(DefaultManager);
103
104end.
105
Note: See TracBrowser for help on using the repository browser.