1 {*********************************************************}
3 { Zeos Database Objects }
4 { Core classes and interfaces }
6 { Originally written by Sergey Seroukhov }
8 {*********************************************************}
10 {@********************************************************}
11 { Copyright (c) 1999-2012 Zeos Development Group }
13 { License Agreement: }
15 { This library is distributed in the hope that it will be }
16 { useful, but WITHOUT ANY WARRANTY; without even the }
17 { implied warranty of MERCHANTABILITY or FITNESS FOR }
18 { A PARTICULAR PURPOSE. See the GNU Lesser General }
19 { Public License for more details. }
21 { The source code of the ZEOS Libraries and packages are }
22 { distributed under the Library GNU General Public }
23 { License (see the file COPYING / COPYING.ZEOS) }
24 { with the following modification: }
25 { As a special exception, the copyright holders of this }
26 { library give you permission to link this library with }
27 { independent modules to produce an executable, }
28 { regardless of the license terms of these independent }
29 { modules, and to copy and distribute the resulting }
30 { executable under terms of your choice, provided that }
31 { you also meet, for each linked independent module, }
32 { the terms and conditions of the license of that module. }
33 { An independent module is a module which is not derived }
34 { from or based on this library. If you modify this }
35 { library, you may extend this exception to your version }
36 { of the library, but you are not obligated to do so. }
37 { If you do not wish to do so, delete this exception }
38 { statement from your version. }
41 { The project web site is located on: }
42 { http://zeos.firmos.at (FORUM) }
43 { http://sourceforge.net/p/zeoslib/tickets/ (BUGTRACKER)}
44 { svn://svn.code.sf.net/p/zeoslib/code-0/trunk (SVN) }
46 { http://www.sourceforge.net/projects/zeoslib. }
49 { Zeos Development Group. }
50 {********************************************************@}
62 ZEOS_MAJOR_VERSION = 7;
63 ZEOS_MINOR_VERSION = 1;
65 ZEOS_STATUS = 'stable';
66 ZEOS_VERSION = '7.1.4-stable';
67 {$IFDEF ENABLE_POOLED}
68 {Pooled Protocol Prefix, including final dot}
69 PooledPrefix = 'pooled.';
75 PDateTime = ^TDateTime;
77 TAggregatedObject = class(TObject)
80 function GetController: IInterface;
83 function QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; virtual;
84 function _AddRef : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
85 function _Release : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
87 function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
88 function _AddRef : longint;stdcall;
89 function _Release : longint;stdcall;
92 constructor Create(const Controller: IInterface);
93 property Controller: IInterface read GetController;
96 TContainedObject = class(TAggregatedObject, IInterface)
99 function QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; override;
101 function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
107 {** Replacement for generic interface type. }
108 IZInterface = IUnknown;
110 {** Represents an interface for all abstract object. }
111 IZObject = interface(IZInterface)
112 ['{EF46E5F7-00CF-4DDA-BED0-057D6686AEE0}']
113 function Equals(const Value: IZInterface): Boolean;
114 function GetHashCode: LongInt;
115 function Clone: IZInterface;
116 function ToString: string;
117 function InstanceOf(const IId: TGUID): Boolean;
120 {** Represents a fake interface for coparable objects. }
121 IZComparable = interface(IZObject)
122 ['{04112081-F07B-4BBF-A757-817816EB67C1}']
125 {** Represents an interface to clone objects. }
126 IZClonnable = interface(IZObject)
127 ['{ECB7F3A4-7B2E-4130-BA66-54A2D43C0149}']
130 {** Represents a generic collection iterator interface. }
131 IZIterator = interface(IZObject)
132 ['{D964DDD0-2308-4D9B-BD36-5810632512F7}']
133 function HasNext: Boolean;
134 function Next: IZInterface;
137 {** Represents a collection of object interfaces. }
138 IZCollection = interface(IZClonnable)
139 ['{51417C87-F992-4CAD-BC53-CF3925DD6E4C}']
141 function Get(Index: Integer): IZInterface;
142 procedure Put(Index: Integer; const Item: IZInterface);
143 function IndexOf(const Item: IZInterface): Integer;
144 function GetCount: Integer;
145 function GetIterator: IZIterator;
147 function First: IZInterface;
148 function Last: IZInterface;
150 function Add(const Item: IZInterface): Integer;
151 procedure Insert(Index: Integer; const Item: IZInterface);
152 function Remove(const Item: IZInterface): Integer;
154 procedure Exchange(Index1, Index2: Integer);
155 procedure Delete(Index: Integer);
158 function Contains(const Item: IZInterface): Boolean;
159 function ContainsAll(const Col: IZCollection): Boolean;
160 function AddAll(const Col: IZCollection): Boolean;
161 function RemoveAll(const Col: IZCollection): Boolean;
163 property Count: Integer read GetCount;
164 property Items[Index: Integer]: IZInterface read Get write Put; default;
167 {** Represents a hash map interface. }
168 IZHashMap = interface(IZClonnable)
169 ['{782C64F4-AD09-4F56-AF2B-E4193A05BBCE}']
171 function Get(const Key: IZInterface): IZInterface;
172 procedure Put(const Key: IZInterface; const Value: IZInterface);
173 function GetKeys: IZCollection;
174 function GetValues: IZCollection;
175 function GetCount: Integer;
177 function Remove(Key: IZInterface): Boolean;
180 property Count: Integer read GetCount;
181 property Keys: IZCollection read GetKeys;
182 property Values: IZCollection read GetValues;
185 {** Represents a stack interface. }
186 IZStack = interface(IZClonnable)
187 ['{8FEA0B3F-0C02-4E70-BD8D-FB0F42D4497B}']
189 function Peek: IZInterface;
190 function Pop: IZInterface;
191 procedure Push(Value: IZInterface);
192 function GetCount: Integer;
194 property Count: Integer read GetCount;
197 {$IFDEF WITH_NEWTOBJECT} // to suppress the overload warning of the Equals overload, Marco. (overload a non overload-declared funtion)
200 {** Implements an abstract interfaced object. }
201 TZAbstractObject = class(TInterfacedObject, IZObject)
203 function Equals(const Value: IZInterface): Boolean; {$IFDEF WITH_NEWTOBJECT}overload;{$ENDIF} virtual;
204 function GetHashCode: LongInt;
205 function Clone: IZInterface; virtual;
206 function ToString: string;{$IFDEF WITH_NEWTOBJECT}override{$ELSE} virtual{$ENDIF} ;
207 function InstanceOf(const IId: TGUID): Boolean;
209 {$IFDEF WITH_NEWTOBJECT}
215 uses ZMessages, ZCompatibility;
219 { TAggregatedObject }
221 constructor TAggregatedObject.Create(const Controller: IInterface);
223 FController := Pointer(Controller);
226 function TAggregatedObject.GetController: IInterface;
228 Result := IInterface(FController);
232 function TAggregatedObject.QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : longint;
234 function TAggregatedObject.QueryInterface(const iid : tguid;out obj) : longint;stdcall;
237 Result := IInterface(FController).QueryInterface(IID, Obj);
240 function TAggregatedObject._AddRef: longint;
242 Result := IInterface(FController)._AddRef;
245 function TAggregatedObject._Release : longint;
247 Result := IInterface(FController)._Release;
253 function TContainedObject.QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
255 function TContainedObject.QueryInterface(const iid : tguid;out obj) : longint;stdcall;
259 if GetInterface(IID, Obj) then
262 Result := E_NOINTERFACE;
270 Checks is the specified value equals to this object.
271 @param Value an interface to some object.
272 @return <code>True</code> if the objects are identical.
274 function TZAbstractObject.Equals(const Value: IZInterface): Boolean;
278 Result := (IZInterface(Self) = Value)
279 or ((Self as IZInterface) = (Value as IZInterface));
285 Gets a unique hash for this object.
286 @return a unique hash for this object.
288 function TZAbstractObject.GetHashCode: LongInt;
290 Result := LongInt(Self);
294 Clones an object instance.
295 @return a clonned object instance.
297 function TZAbstractObject.Clone: IZInterface;
299 raise Exception.Create(SClonningIsNotSupported);
304 Checks is this object implements a specified interface.
305 @param IId an interface id.
306 @return <code>True</code> if this object support the interface.
308 function TZAbstractObject.InstanceOf(const IId: TGUID): Boolean;
310 Result := GetInterfaceEntry(IId) <> nil;
314 Converts this object into the string representation.
315 @return a string representation for this object.
317 function TZAbstractObject.ToString: string;
319 Result := Format('%s <%p>', [ClassName, Pointer(Self)])