1 {*********************************************************}
3 { Zeos Database Objects }
4 { Database Connection Component }
6 { Originally written by una.bicicleta }
7 {*********************************************************}
9 {@********************************************************}
10 { Copyright (c) 1999-2012 Zeos Development Group }
12 { License Agreement: }
14 { This library is distributed in the hope that it will be }
15 { useful, but WITHOUT ANY WARRANTY; without even the }
16 { implied warranty of MERCHANTABILITY or FITNESS FOR }
17 { A PARTICULAR PURPOSE. See the GNU Lesser General }
18 { Public License for more details. }
20 { The source code of the ZEOS Libraries and packages are }
21 { distributed under the Library GNU General Public }
22 { License (see the file COPYING / COPYING.ZEOS) }
23 { with the following modification: }
24 { As a special exception, the copyright holders of this }
25 { library give you permission to link this library with }
26 { independent modules to produce an executable, }
27 { regardless of the license terms of these independent }
28 { modules, and to copy and distribute the resulting }
29 { executable under terms of your choice, provided that }
30 { you also meet, for each linked independent module, }
31 { the terms and conditions of the license of that module. }
32 { An independent module is a module which is not derived }
33 { from or based on this library. If you modify this }
34 { library, you may extend this exception to your version }
35 { of the library, but you are not obligated to do so. }
36 { If you do not wish to do so, delete this exception }
37 { statement from your version. }
40 { The project web site is located on: }
41 { http://zeos.firmos.at (FORUM) }
42 { http://sourceforge.net/p/zeoslib/tickets/ (BUGTRACKER)}
43 { svn://svn.code.sf.net/p/zeoslib/code-0/trunk (SVN) }
45 { http://www.sourceforge.net/projects/zeoslib. }
48 { Zeos Development Group. }
49 {********************************************************@}
51 unit ZConnectionGroup;
57 SysUtils, Classes, {$IFDEF MSEgui}mclasses,{$ENDIF} Forms, Dialogs,
58 ZDbcIntfs,ZCompatibility;
61 mask = 'æææ#2ææ0#ææ39æ-VFFVæææ'; { define your own mask }
64 TZConnectionGroup = class;
65 TZConnectionGroupLink = class;
67 TZConnectionGroupLink = class(TObject)
70 FOnChange: TNotifyEvent;
72 destructor Destroy; override;
75 property OnChange: TNotifyEvent read FOnChange write FOnChange;
76 property Sender: TObject read FSender write FSender;
80 TZConnectionGroup = class(TComponent)
82 FOnChange: TNotifyEvent;
83 procedure DoChange(Sender: TObject);
96 procedure UnregisterAllDataSets;
97 procedure SetUser(const Value: string);
98 procedure SetPassword(const Value: string);
99 procedure DefineProperties(filer: tfiler);override;
101 procedure SetProtocol(const Value: string);
102 procedure SetHostName(const Value: string);
103 procedure SetConnPort(const Value: integer);
104 procedure SetDatabase(const Value: string);
105 procedure SetLibLocation(const Value: String);
106 //procedure SetCatalog(const Value: string);
108 function Encrypt(const str: string): string; //virtual;
109 function Decrypt(const str: string): string; //virtual;
111 constructor Create(AOwner: TComponent); override;
112 destructor Destroy; override;
113 procedure ReadPass(reader:treader);
114 procedure WritePass(writer:twriter);
115 procedure ReadUser(reader:treader);
116 procedure WriteUser(writer:twriter);
117 procedure RegisterChanges(Value: TZConnectionGroupLink);
118 procedure UnregisterChanges(Value: TZConnectionGroupLink);
120 property Protocol: string read FProtocol write SetProtocol;
121 property HostName: string read FHostName write SetHostName;
122 property Port: Integer read FPort write SetConnPort default 0;
123 property Database: string read FDatabase write SetDatabase;
124 property User: string read FUser write SetUser stored false;
125 property Password: string read FPassword write SetPassword stored false;
126 property LibraryLocation: String read FLibLocation write SetLibLocation;
127 //property Catalog: string read FCatalog write SetCatalog;
128 property OnChange: TNotifyEvent read FOnChange write FOnChange;
130 // add another property or event ?
136 // === { TZConnectionGroupLink } ====================================================
137 destructor TZConnectionGroupLink.Destroy;
139 if Sender is TZConnectionGroup then
140 TZConnectionGroup(Sender).UnregisterChanges(Self);
144 procedure TZConnectionGroupLink.Change;
146 if Assigned(FOnChange) then
151 // === { TZConnectionGroup } =============================================
152 constructor TZConnectionGroup.Create(AOwner: TComponent);
154 inherited Create(AOwner);
155 FClients := tList.Create;
158 destructor TZConnectionGroup.Destroy;
160 UnregisterAllDataSets;
166 procedure TZConnectionGroup.DoChange(Sender: TObject);
171 procedure TZConnectionGroup.Change;
174 if Assigned(FOnChange) then
178 if FClients <> nil then
179 for I := 0 to FClients.Count - 1 do
180 TZConnectionGroupLink(FClients[I]).Change;
183 // === { TZConnectionGroup } =============================================
184 function TZConnectionGroup.Decrypt(const str: string): string;
188 for n:=1 to length(str) do
190 chr(ord(str[n]) xor ord(mask[((n-1) mod length(mask)) +1]));
193 function TZConnectionGroup.Encrypt(const str: string): string;
195 result:=Decrypt(str); { symmetrical encryption }
198 procedure TZConnectionGroup.ReadPass(reader:treader);
200 reader.readlistbegin;
201 FPassword := Decrypt(reader.readstring);
205 procedure TZConnectionGroup.WritePass(writer:twriter);
207 writer.writelistbegin;
208 writer.writestring(Encrypt(FPassword));
212 procedure TZConnectionGroup.ReadUser(reader:treader);
214 reader.readlistbegin;
215 FUser := Decrypt(reader.readstring);
219 procedure TZConnectionGroup.WriteUser(writer:twriter);
221 writer.writelistbegin;
222 writer.writestring(Encrypt(FUser));
226 procedure TZConnectionGroup.DefineProperties(filer: tfiler);
228 inherited defineproperties(filer);
229 filer.DefineProperty('str1',ReadUser,WriteUser,true);
230 filer.DefineProperty('str2',ReadPass,WritePass,true);
234 procedure TZConnectionGroup.SetUser(const Value: string);
236 if FUser <> Value then
243 procedure TZConnectionGroup.SetPassword(const Value: string);
245 if FPassword <> Value then
252 procedure TZConnectionGroup.SetProtocol(const Value: string);
254 if FProtocol <> Value then
261 procedure TZConnectionGroup.SetHostName(const Value: string);
263 if FHostName <> Value then
270 procedure TZConnectionGroup.SetDatabase(const Value: string);
272 if FDatabase <> Value then
279 procedure TZConnectionGroup.SetLibLocation(const Value: String);
281 if FLibLocation <> Value then
283 FLibLocation := Value;
289 procedure TZConnectionGroup.SetCatalog(const Value: string);
291 if FCatalog <> Value then
299 procedure TZConnectionGroup.SetConnPort(const Value: integer);
301 if FPort <> Value then
308 procedure TZConnectionGroup.UnregisterAllDataSets;
311 Current: TZConnectionGroupLink;
313 for I := FClients.Count - 1 downto 0 do
315 Current := TZConnectionGroupLink(FClients[I]);
316 FClients.Remove(Current);
325 procedure TZConnectionGroup.RegisterChanges(Value: TZConnectionGroupLink);
327 Value.Sender := Self;
328 if FClients <> nil then
332 procedure TZConnectionGroup.UnregisterChanges(Value: TZConnectionGroupLink);
336 if FClients <> nil then
337 for I := 0 to FClients.Count - 1 do
338 if FClients[I] = Value then