1 {*********************************************************}
3 { Zeos Database Objects }
4 { Grouped 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 ZGroupedConnection;
57 SysUtils, Messages, Classes, ZDbcIntfs, DB,Forms,
58 ZCompatibility, ZAbstractConnection, ZSequence, Dialogs,
59 ZConnectionGroup {$IFDEF FPC}, LMessages{$ENDIF};
62 const CM_ZCONNECTIONGROUPCHANGED = WM_USER + 100;
63 const CM_ZCONNECTIONGROUPCHANGE = WM_USER + 101;
65 const CM_ZCONNECTIONGROUPCHANGED = LM_USER + 100;
66 const CM_ZCONNECTIONGROUPCHANGE = LM_USER + 101;
70 TMsgZDbConnecitionChange = record
73 ZConnectionGroup: TZConnectionGroup;
79 TZGroupedConnection = class(tZAbstractConnection)
81 FZConnectionGroup: TZConnectionGroup;
82 FZConnectionGroupLink: TZConnectionGroupLink;
83 procedure SetConnectionGroup(Value: TZConnectionGroup);
84 procedure Notification(AComponent: TComponent; Operation: TOperation);
87 function getUser: string;
88 function getPassword: string;
89 function getHostName: string;
90 function getDatabase: string;
91 function GetLibLocation: String;
92 //function getCatalog: string;
93 procedure DoZConnectionGroupChange(Sender: TObject);
94 procedure ParentZConnectionGroupChange(var Msg: TMessage);
96 property ConnectionGroup: TZConnectionGroup read FZConnectionGroup write SetConnectionGroup;
98 constructor Create(AOwner: TComponent); override;
99 destructor Destroy; override;
105 procedure InternalZConnectionGroupChanged(AControl: TComponent; AZConnectionGroup: TZConnectionGroup);
107 Msg: TMsgZDbConnecitionChange;
109 Msg.Msg := CM_ZCONNECTIONGROUPCHANGED;
110 Msg.Sender := AControl;
111 Msg.ZConnectionGroup := AZConnectionGroup;
113 //AControl.Broadcast(Msg);
116 // === { TZGroupedConnection } =============================================
117 constructor TZGroupedConnection .Create(AOwner: TComponent);
119 inherited Create(AOwner);
120 FZConnectionGroupLink := TZConnectionGroupLink.Create;
121 FZConnectionGroupLink.OnChange := DoZConnectionGroupChange;
124 destructor TZGroupedConnection .Destroy;
126 FZConnectionGroupLink.Free;
130 procedure TZGroupedConnection .DoZConnectionGroupChange(Sender: TObject);
132 if (Sender is TZConnectionGroup) then
134 FURL.UserName := (Sender as TZConnectionGroup).User;
135 FURL.Protocol := (Sender as TZConnectionGroup).Protocol;
136 FURL.Password := (Sender as TZConnectionGroup).Password;
137 FURL.HostName := (Sender as TZConnectionGroup).HostName;
138 FURL.Database := (Sender as TZConnectionGroup).Database;
139 FURL.LibLocation := (Sender as TZConnectionGroup).LibraryLocation;
143 procedure TZGroupedConnection .ParentZConnectionGroupChange(var Msg: TMessage);
145 InternalZConnectionGroupChanged(Self, FZConnectionGroup);
148 procedure TZGroupedConnection .Notification(AComponent: TComponent;
149 Operation: TOperation);
151 inherited Notification(AComponent, Operation);
153 if (Operation = opRemove) then
155 if (AComponent is TDataset) then
156 UnregisterDataSet(TDataset(AComponent));
157 if (AComponent is TZSequence) then
158 UnregisterSequence(TZSequence(AComponent));
159 if (AComponent = FZConnectionGroup) then
160 FZConnectionGroup := nil;
164 procedure TZGroupedConnection .SetConnectionGroup(Value: TZConnectionGroup);
166 if FZConnectionGroup<>nil then
167 FZConnectionGroup.UnRegisterChanges(FZConnectionGroupLink);
169 FZConnectionGroup := Value;
172 FZConnectionGroup.RegisterChanges(FZConnectionGroupLink);
173 FURL.UserName := FZConnectionGroup.User;
174 FURL.Protocol := FZConnectionGroup.Protocol;
175 FURL.Password := FZConnectionGroup.Password;
176 FURL.HostName := FZConnectionGroup.HostName;
177 FURL.Database := FZConnectionGroup.Database;
178 FURL.LibLocation := FZConnectionGroup.LibraryLocation;
180 InternalZConnectionGroupChanged(Self, Value);
183 function TZGroupedConnection .getUser: string;
185 if FZConnectionGroup <> nil then
187 FURL.UserName := FZConnectionGroup.User;
188 Result := FURL.UserName;
195 function TZGroupedConnection .getProtocol: string;
197 if FZConnectionGroup <> nil then
199 FProtocol := FZConnectionGroup.Protocol;
207 function TZGroupedConnection .getPassword: string;
209 if FZConnectionGroup <> nil then
211 FURL.Password := FZConnectionGroup.Password;
212 Result := FURL.Password;
218 function TZGroupedConnection .getHostName: string;
220 if FZConnectionGroup <> nil then
222 FURL.HostName := FZConnectionGroup.HostName;
223 Result := FURL.HostName;
229 function TZGroupedConnection .getDatabase: string;
231 if FZConnectionGroup <> nil then
233 FURL.Database := FZConnectionGroup.Database;
234 Result := FURL.Database;
240 function TZGroupedConnection.GetLibLocation: String;
242 if FZConnectionGroup <> nil then
244 FURL.LibLocation := FZConnectionGroup.LibraryLocation;
245 Result := FURL.LibLocation;
248 FURL.LibLocation := '';
252 function TZGroupedConnection .getCatalog: string;
254 if FZConnectionGroup <> nil then
256 FCatalog := FZConnectionGroup.Catalog;