zeoslib  UNKNOWN
 All Files
ZGroupedConnection.pas
Go to the documentation of this file.
1 {*********************************************************}
2 { }
3 { Zeos Database Objects }
4 { Grouped Database Connection Component }
5 { }
6 { Originally written by una.bicicleta }
7 {*********************************************************}
8 
9 {@********************************************************}
10 { Copyright (c) 1999-2012 Zeos Development Group }
11 { }
12 { License Agreement: }
13 { }
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. }
19 { }
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. }
38 { }
39 { }
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) }
44 { }
45 { http://www.sourceforge.net/projects/zeoslib. }
46 { }
47 { }
48 { Zeos Development Group. }
49 {********************************************************@}
50 
51 unit ZGroupedConnection;
52 
53 interface
54 {$I ZComponent.inc}
55 
56 uses
57  SysUtils, Messages, Classes, ZDbcIntfs, DB,Forms,
58  ZCompatibility, ZAbstractConnection, ZSequence, Dialogs,
59  ZConnectionGroup {$IFDEF FPC}, LMessages{$ENDIF};
60 
61 {$IFNDEF FPC}
62  const CM_ZCONNECTIONGROUPCHANGED = WM_USER + 100;
63  const CM_ZCONNECTIONGROUPCHANGE = WM_USER + 101;
64 {$ELSE}
65 const CM_ZCONNECTIONGROUPCHANGED = LM_USER + 100;
66 const CM_ZCONNECTIONGROUPCHANGE = LM_USER + 101;
67 {$ENDIF}
68 
69 type
70  TMsgZDbConnecitionChange = record
71  Msg: Cardinal;
72  Sender: TComponent;
73  ZConnectionGroup: TZConnectionGroup;
74  Result: Longint;
75  end;
76 
77 {$HINTS OFF}
78 type
79  TZGroupedConnection = class(tZAbstractConnection)
80  protected
81  FZConnectionGroup: TZConnectionGroup;
82  FZConnectionGroupLink: TZConnectionGroupLink;
83  procedure SetConnectionGroup(Value: TZConnectionGroup);
84  procedure Notification(AComponent: TComponent; Operation: TOperation);
85  override;
86  private
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);
95  published
96  property ConnectionGroup: TZConnectionGroup read FZConnectionGroup write SetConnectionGroup;
97  public
98  constructor Create(AOwner: TComponent); override;
99  destructor Destroy; override;
100  end;
101 {$HINTS ON}
102 
103 implementation
104 
105 procedure InternalZConnectionGroupChanged(AControl: TComponent; AZConnectionGroup: TZConnectionGroup);
106 var
107  Msg: TMsgZDbConnecitionChange;
108 begin
109  Msg.Msg := CM_ZCONNECTIONGROUPCHANGED;
110  Msg.Sender := AControl;
111  Msg.ZConnectionGroup := AZConnectionGroup;
112  Msg.Result := 0;
113  //AControl.Broadcast(Msg);
114 end;
115 
116 // === { TZGroupedConnection } =============================================
117 constructor TZGroupedConnection .Create(AOwner: TComponent);
118 begin
119  inherited Create(AOwner);
120  FZConnectionGroupLink := TZConnectionGroupLink.Create;
121  FZConnectionGroupLink.OnChange := DoZConnectionGroupChange;
122 end;
123 
124 destructor TZGroupedConnection .Destroy;
125 begin
126  FZConnectionGroupLink.Free;
127  inherited Destroy;
128 end;
129 
130 procedure TZGroupedConnection .DoZConnectionGroupChange(Sender: TObject);
131 begin
132  if (Sender is TZConnectionGroup) then
133  begin
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;
140  end;
141 end;
142 
143 procedure TZGroupedConnection .ParentZConnectionGroupChange(var Msg: TMessage);
144 begin
145  InternalZConnectionGroupChanged(Self, FZConnectionGroup);
146 end;
147 
148 procedure TZGroupedConnection .Notification(AComponent: TComponent;
149  Operation: TOperation);
150 begin
151  inherited Notification(AComponent, Operation);
152 
153  if (Operation = opRemove) then
154  begin
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;
161  end;
162 end;
163 
164 procedure TZGroupedConnection .SetConnectionGroup(Value: TZConnectionGroup);
165 begin
166  if FZConnectionGroup<>nil then
167  FZConnectionGroup.UnRegisterChanges(FZConnectionGroupLink);
168 
169  FZConnectionGroup := Value;
170  if Value <> nil then
171  begin
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;
179  end;
180  InternalZConnectionGroupChanged(Self, Value);
181 end;
182 
183 function TZGroupedConnection .getUser: string;
184 begin
185  if FZConnectionGroup <> nil then
186  begin
187  FURL.UserName := FZConnectionGroup.User;
188  Result := FURL.UserName;
189  end
190  else
191  FURL.UserName := '';
192 end;
193 
194 {
195 function TZGroupedConnection .getProtocol: string;
196 begin
197  if FZConnectionGroup <> nil then
198  begin
199  FProtocol := FZConnectionGroup.Protocol;
200  Result := FProtocol;
201  end
202  else
203  FProtocol := '';
204 end;
205 }
206 
207 function TZGroupedConnection .getPassword: string;
208 begin
209  if FZConnectionGroup <> nil then
210  begin
211  FURL.Password := FZConnectionGroup.Password;
212  Result := FURL.Password;
213  end
214  else
215  FURL.Password := '';
216 end;
217 
218 function TZGroupedConnection .getHostName: string;
219 begin
220  if FZConnectionGroup <> nil then
221  begin
222  FURL.HostName := FZConnectionGroup.HostName;
223  Result := FURL.HostName;
224  end
225  else
226  FURL.HostName := '';
227 end;
228 
229 function TZGroupedConnection .getDatabase: string;
230 begin
231  if FZConnectionGroup <> nil then
232  begin
233  FURL.Database := FZConnectionGroup.Database;
234  Result := FURL.Database;
235  end
236  else
237  FURL.Database := '';
238 end;
239 
240 function TZGroupedConnection.GetLibLocation: String;
241 begin
242  if FZConnectionGroup <> nil then
243  begin
244  FURL.LibLocation := FZConnectionGroup.LibraryLocation;
245  Result := FURL.LibLocation;
246  end
247  else
248  FURL.LibLocation := '';
249 end;
250 
251 {
252 function TZGroupedConnection .getCatalog: string;
253 begin
254  if FZConnectionGroup <> nil then
255  begin
256  FCatalog := FZConnectionGroup.Catalog;
257  Result := FCatalog;
258  end
259  else
260  FCatalog := '';
261 end;
262 }
263 
264 end.