db.pp 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt, member of the
  4. Free Pascal development team
  5. DB header file with interface section.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit db;
  13. {$mode objfpc}
  14. {$h+}
  15. interface
  16. uses Classes,Sysutils,Variants;
  17. const
  18. dsMaxBufferCount = MAXINT div 8;
  19. dsMaxStringSize = 8192;
  20. // Used in AsBoolean for string fields to determine
  21. // whether it's true or false.
  22. YesNoChars : Array[Boolean] of char = ('N', 'Y');
  23. SQLDelimiterCharacters = [';',',',' ','(',')',#13,#10,#9];
  24. type
  25. {LargeInt}
  26. LargeInt = Int64;
  27. PLargeInt= ^LargeInt;
  28. { Auxiliary type }
  29. TStringFieldBuffer = Array[0..dsMaxStringSize] of Char;
  30. { Misc Dataset types }
  31. TDataSetState = (dsInactive, dsBrowse, dsEdit, dsInsert, dsSetKey,
  32. dsCalcFields, dsFilter, dsNewValue, dsOldValue, dsCurValue, dsBlockRead,
  33. dsInternalCalc, dsOpening);
  34. TDataEvent = (deFieldChange, deRecordChange, deDataSetChange,
  35. deDataSetScroll, deLayoutChange, deUpdateRecord, deUpdateState,
  36. deCheckBrowseMode, dePropertyChange, deFieldListChange, deFocusControl,
  37. deParentScroll,deConnectChange,deReconcileError,deDisabledStateChange);
  38. TUpdateStatus = (usUnmodified, usModified, usInserted, usDeleted);
  39. TUpdateStatusSet = SET OF TUpdateStatus;
  40. TUpdateMode = (upWhereAll, upWhereChanged, upWhereKeyOnly);
  41. TResolverResponse = (rrSkip, rrAbort, rrMerge, rrApply, rrIgnore);
  42. TProviderFlag = (pfInUpdate, pfInWhere, pfInKey, pfHidden);
  43. TProviderFlags = set of TProviderFlag;
  44. { Forward declarations }
  45. TFieldDef = class;
  46. TFieldDefs = class;
  47. TField = class;
  48. TFields = Class;
  49. TDataSet = class;
  50. TDataBase = Class;
  51. TDatasource = Class;
  52. TDatalink = Class;
  53. TDBTransaction = Class;
  54. { Exception classes }
  55. EDatabaseError = class(Exception);
  56. EUpdateError = class(EDatabaseError)
  57. private
  58. FContext : String;
  59. FErrorCode : integer;
  60. FOriginalException : Exception;
  61. FPreviousError : Integer;
  62. public
  63. constructor Create(NativeError, Context : String;
  64. ErrCode, PrevError : integer; E: Exception);
  65. Destructor Destroy; override;
  66. property Context : String read FContext;
  67. property ErrorCode : integer read FErrorcode;
  68. property OriginalExcaption : Exception read FOriginalException;
  69. property PreviousError : Integer read FPreviousError;
  70. end;
  71. { TFieldDef }
  72. TFieldClass = class of TField;
  73. {
  74. TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
  75. ftBoolean, ftFloat, ftDate, ftTime, ftDateTime,
  76. ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic,
  77. ftFmtMemo, ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor);
  78. }
  79. TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
  80. ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime,
  81. ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo,
  82. ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar,
  83. ftWideString, ftLargeint, ftADT, ftArray, ftReference,
  84. ftDataSet, ftOraBlob, ftOraClob, ftVariant, ftInterface,
  85. ftIDispatch, ftGuid, ftTimeStamp, ftFMTBcd);
  86. { Part of DBCommon, but temporary defined here (bug 8206) }
  87. TFieldMap = array[TFieldType] of Byte;
  88. { TDateTimeRec }
  89. TDateTimeAlias = type TDateTime;
  90. PDateTimeRec = ^TdateTimeRec;
  91. TDateTimeRec = record
  92. case TFieldType of
  93. ftDate: (Date: Longint);
  94. ftTime: (Time: Longint);
  95. ftDateTime: (DateTime: TDateTimeAlias);
  96. end;
  97. TFieldAttribute = (faHiddenCol, faReadonly, faRequired, faLink, faUnNamed, faFixed);
  98. TFieldAttributes = set of TFieldAttribute;
  99. { TFieldDef }
  100. TFieldDef = class(TCollectionItem)
  101. Private
  102. FDataType : TFieldType;
  103. FFieldNo : Longint;
  104. FInternalCalcField : Boolean;
  105. FPrecision : Longint;
  106. FRequired : Boolean;
  107. FSize : Word;
  108. FName : String;
  109. FDisplayName : String;
  110. FAttributes : TFieldAttributes;
  111. Function GetFieldClass : TFieldClass;
  112. procedure SetAttributes(AValue: TFieldAttributes);
  113. procedure SetDataType(AValue: TFieldType);
  114. procedure SetPrecision(const AValue: Longint);
  115. procedure SetSize(const AValue: Word);
  116. procedure SetRequired(const AValue: Boolean);
  117. protected
  118. function GetDisplayName: string; override;
  119. procedure SetDisplayName(const AValue: string); override;
  120. public
  121. constructor Create(AOwner: TFieldDefs; const AName: string;
  122. ADataType: TFieldType; ASize: Word; ARequired: Boolean; AFieldNo: Longint); overload;
  123. destructor Destroy; override;
  124. procedure Assign(APersistent: TPersistent); override;
  125. function CreateField(AOwner: TComponent): TField;
  126. property FieldClass: TFieldClass read GetFieldClass;
  127. property FieldNo: Longint read FFieldNo;
  128. property InternalCalcField: Boolean read FInternalCalcField write FInternalCalcField;
  129. property Required: Boolean read FRequired write SetRequired;
  130. Published
  131. property Attributes: TFieldAttributes read FAttributes write SetAttributes default [];
  132. property Name: string read FName write FName; // Must move to TNamedItem
  133. property DisplayName : string read FDisplayName write FDisplayName; // Must move to TNamedItem
  134. property DataType: TFieldType read FDataType write SetDataType;
  135. property Precision: Longint read FPrecision write SetPrecision;
  136. property Size: Word read FSize write SetSize;
  137. end;
  138. { TFieldDefs }
  139. TFieldDefs = class(TOwnedCollection)
  140. private
  141. FUpdated: Boolean;
  142. FHiddenFields : Boolean;
  143. function GetItem(Index: Longint): TFieldDef;
  144. function GetDataset: TDataset;
  145. procedure SetItem(Index: Longint; const AValue: TFieldDef);
  146. protected
  147. procedure SetItemName(AItem: TCollectionItem); override;
  148. public
  149. constructor Create(ADataSet: TDataSet);
  150. // destructor Destroy; override;
  151. procedure Add(const AName: string; ADataType: TFieldType; ASize: Word; ARequired: Boolean);
  152. procedure Add(const AName: string; ADataType: TFieldType; ASize: Word);
  153. procedure Add(const AName: string; ADataType: TFieldType);
  154. Function AddFieldDef : TFieldDef;
  155. procedure Assign(FieldDefs: TFieldDefs); overload;
  156. // procedure Clear;
  157. // procedure Delete(Index: Longint);
  158. function Find(const AName: string): TFieldDef;
  159. function IndexOf(const AName: string): Longint;
  160. procedure Update; overload;
  161. Property HiddenFields : Boolean Read FHiddenFields Write FHiddenFields;
  162. property Items[Index: Longint]: TFieldDef read GetItem write SetItem; default;
  163. property Dataset: TDataset read GetDataset;
  164. property Updated: Boolean read FUpdated write FUpdated;
  165. end;
  166. { TField }
  167. TFieldKind = (fkData, fkCalculated, fkLookup, fkInternalCalc);
  168. TFieldKinds = Set of TFieldKind;
  169. TFieldNotifyEvent = procedure(Sender: TField) of object;
  170. TFieldGetTextEvent = procedure(Sender: TField; var Text: string;
  171. DisplayText: Boolean) of object;
  172. TFieldSetTextEvent = procedure(Sender: TField; const Text: string) of object;
  173. TFieldRef = ^TField;
  174. TFieldChars = set of Char;
  175. PLookupListRec = ^TLookupListRec;
  176. TLookupListRec = record
  177. Key: Variant;
  178. Value: Variant;
  179. end;
  180. { TLookupList }
  181. TLookupList = class(TObject)
  182. private
  183. FList: TList;
  184. public
  185. constructor Create;
  186. destructor Destroy; override;
  187. procedure Add(const AKey, AValue: Variant);
  188. procedure Clear;
  189. function ValueOfKey(const AKey: Variant): Variant;
  190. end;
  191. { TField }
  192. TField = class(TComponent)
  193. Private
  194. FAlignMent : TAlignment;
  195. FAttributeSet : String;
  196. FCalculated : Boolean;
  197. FConstraintErrorMessage : String;
  198. FCustomConstraint : String;
  199. FDataSet : TDataSet;
  200. // FDataSize : Word;
  201. FDataType : TFieldType;
  202. FDefaultExpression : String;
  203. FDisplayLabel : String;
  204. FDisplayWidth : Longint;
  205. FFieldKind : TFieldKind;
  206. FFieldName : String;
  207. FFieldNo : Longint;
  208. FFields : TFields;
  209. FHasConstraints : Boolean;
  210. FImportedConstraint : String;
  211. FIsIndexField : Boolean;
  212. FKeyFields : String;
  213. FLookupCache : Boolean;
  214. FLookupDataSet : TDataSet;
  215. FLookupKeyfields : String;
  216. FLookupresultField : String;
  217. FLookupList: TLookupList;
  218. FOffset : Word;
  219. FOnChange : TFieldNotifyEvent;
  220. FOnGetText: TFieldGetTextEvent;
  221. FOnSetText: TFieldSetTextEvent;
  222. FOnValidate: TFieldNotifyEvent;
  223. FOrigin : String;
  224. FReadOnly : Boolean;
  225. FRequired : Boolean;
  226. FSize : Word;
  227. FValidChars : TFieldChars;
  228. FValueBuffer : Pointer;
  229. FValidating : Boolean;
  230. FVisible : Boolean;
  231. FProviderFlags : TProviderFlags;
  232. Function GetIndex : longint;
  233. procedure SetAlignment(const AValue: TAlignMent);
  234. procedure SetIndex(const AValue: Integer);
  235. Procedure SetDataset(AValue : TDataset);
  236. function GetDisplayText: String;
  237. function GetEditText: String;
  238. procedure SetEditText(const AValue: string);
  239. procedure SetDisplayLabel(const AValue: string);
  240. procedure SetDisplayWidth(const AValue: Longint);
  241. function GetDisplayWidth: integer;
  242. procedure SetReadOnly(const AValue: Boolean);
  243. procedure SetVisible(const AValue: Boolean);
  244. function IsDisplayStored : Boolean;
  245. function GetLookupList: TLookupList;
  246. procedure CalcLookupValue;
  247. protected
  248. function AccessError(const TypeName: string): EDatabaseError;
  249. procedure CheckInactive;
  250. class procedure CheckTypeSize(AValue: Longint); virtual;
  251. procedure Change; virtual;
  252. procedure DataChanged;
  253. procedure FreeBuffers; virtual;
  254. function GetAsBoolean: Boolean; virtual;
  255. function GetAsCurrency: Currency; virtual;
  256. function GetAsLargeInt: LargeInt; virtual;
  257. function GetAsDateTime: TDateTime; virtual;
  258. function GetAsFloat: Double; virtual;
  259. function GetAsLongint: Longint; virtual;
  260. function GetAsInteger: Longint; virtual;
  261. function GetAsVariant: variant; virtual;
  262. function GetOldValue: variant; virtual;
  263. function GetAsString: string; virtual;
  264. function GetCanModify: Boolean; virtual;
  265. function GetClassDesc: String; virtual;
  266. function GetDataSize: Word; virtual;
  267. function GetDefaultWidth: Longint; virtual;
  268. function GetDisplayName : String;
  269. function GetCurValue: Variant; virtual;
  270. function GetNewValue: Variant; virtual;
  271. function GetIsNull: Boolean; virtual;
  272. function GetParentComponent: TComponent; override;
  273. procedure GetText(var AText: string; ADisplayText: Boolean); virtual;
  274. function HasParent: Boolean; override;
  275. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  276. procedure PropertyChanged(LayoutAffected: Boolean);
  277. procedure ReadState(Reader: TReader); override;
  278. procedure SetAsBoolean(AValue: Boolean); virtual;
  279. procedure SetAsCurrency(AValue: Currency); virtual;
  280. procedure SetAsDateTime(AValue: TDateTime); virtual;
  281. procedure SetAsFloat(AValue: Double); virtual;
  282. procedure SetAsLongint(AValue: Longint); virtual;
  283. procedure SetAsInteger(AValue: Integer); virtual;
  284. procedure SetAsLargeint(AValue: Largeint); virtual;
  285. procedure SetAsVariant(AValue: variant); virtual;
  286. procedure SetAsString(const AValue: string); virtual;
  287. procedure SetDataType(AValue: TFieldType);
  288. procedure SetNewValue(const AValue: Variant);
  289. procedure SetSize(AValue: Word); virtual;
  290. procedure SetParentComponent(AParent: TComponent); override;
  291. procedure SetText(const AValue: string); virtual;
  292. procedure SetVarValue(const AValue: Variant); virtual;
  293. public
  294. constructor Create(AOwner: TComponent); override;
  295. destructor Destroy; override;
  296. procedure Assign(Source: TPersistent); override;
  297. procedure AssignValue(const AValue: TVarRec);
  298. procedure Clear; virtual;
  299. procedure FocusControl;
  300. function GetData(Buffer: Pointer): Boolean;
  301. function GetData(Buffer: Pointer; NativeFormat : Boolean): Boolean;
  302. class function IsBlob: Boolean; virtual;
  303. function IsValidChar(InputChar: Char): Boolean; virtual;
  304. procedure RefreshLookupList;
  305. procedure SetData(Buffer: Pointer);
  306. procedure SetData(Buffer: Pointer; NativeFormat : Boolean);
  307. procedure SetFieldType(AValue: TFieldType); virtual;
  308. procedure Validate(Buffer: Pointer);
  309. property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;
  310. property AsCurrency: Currency read GetAsCurrency write SetAsCurrency;
  311. property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
  312. property AsFloat: Double read GetAsFloat write SetAsFloat;
  313. property AsLongint: Longint read GetAsLongint write SetAsLongint;
  314. property AsLargeInt: LargeInt read GetAsLargeInt write SetAsLargeInt;
  315. property AsInteger: Integer read GetAsInteger write SetAsInteger;
  316. property AsString: string read GetAsString write SetAsString;
  317. property AsVariant: variant read GetAsVariant write SetAsVariant;
  318. property AttributeSet: string read FAttributeSet write FAttributeSet;
  319. property Calculated: Boolean read FCalculated write FCalculated;
  320. property CanModify: Boolean read GetCanModify;
  321. property CurValue: Variant read GetCurValue;
  322. property DataSet: TDataSet read FDataSet write SetDataSet;
  323. property DataSize: Word read GetDataSize;
  324. property DataType: TFieldType read FDataType;
  325. property DisplayName: String Read GetDisplayName;
  326. property DisplayText: String read GetDisplayText;
  327. property FieldNo: Longint read FFieldNo;
  328. property IsIndexField: Boolean read FIsIndexField;
  329. property IsNull: Boolean read GetIsNull;
  330. property NewValue: Variant read GetNewValue write SetNewValue;
  331. property Offset: word read FOffset;
  332. property Size: Word read FSize write FSize;
  333. property Text: string read GetEditText write SetEditText;
  334. property ValidChars : TFieldChars Read FValidChars;
  335. property Value: variant read GetAsVariant write SetAsVariant;
  336. property OldValue: variant read GetOldValue;
  337. property LookupList: TLookupList read GetLookupList;
  338. published
  339. property AlignMent : TAlignMent Read FAlignMent write SetAlignment default taLeftJustify;
  340. property CustomConstraint: string read FCustomConstraint write FCustomConstraint;
  341. property ConstraintErrorMessage: string read FConstraintErrorMessage write FConstraintErrorMessage;
  342. property DefaultExpression: string read FDefaultExpression write FDefaultExpression;
  343. property DisplayLabel : string read GetDisplayName write SetDisplayLabel stored IsDisplayStored;
  344. property DisplayWidth: Longint read GetDisplayWidth write SetDisplayWidth;
  345. property FieldKind: TFieldKind read FFieldKind write FFieldKind;
  346. property FieldName: string read FFieldName write FFieldName;
  347. property HasConstraints: Boolean read FHasConstraints;
  348. property Index: Longint read GetIndex write SetIndex;
  349. property ImportedConstraint: string read FImportedConstraint write FImportedConstraint;
  350. property LookupDataSet: TDataSet read FLookupDataSet write FLookupDataSet;
  351. property LookupKeyFields: string read FLookupKeyFields write FLookupKeyFields;
  352. property LookupResultField: string read FLookupResultField write FLookupResultField;
  353. property KeyFields: string read FKeyFields write FKeyFields;
  354. property LookupCache: Boolean read FLookupCache write FLookupCache;
  355. property Origin: string read FOrigin write FOrigin;
  356. property ProviderFlags : TProviderFlags read FProviderFlags write FProviderFlags;
  357. property ReadOnly: Boolean read FReadOnly write SetReadOnly;
  358. property Required: Boolean read FRequired write FRequired;
  359. property Visible: Boolean read FVisible write SetVisible default True;
  360. property OnChange: TFieldNotifyEvent read FOnChange write FOnChange;
  361. property OnGetText: TFieldGetTextEvent read FOnGetText write FOnGetText;
  362. property OnSetText: TFieldSetTextEvent read FOnSetText write FOnSetText;
  363. property OnValidate: TFieldNotifyEvent read FOnValidate write FOnValidate;
  364. end;
  365. { TStringField }
  366. TStringField = class(TField)
  367. private
  368. FFixedChar : boolean;
  369. FTransliterate : Boolean;
  370. protected
  371. class procedure CheckTypeSize(AValue: Longint); override;
  372. function GetAsBoolean: Boolean; override;
  373. function GetAsDateTime: TDateTime; override;
  374. function GetAsFloat: Double; override;
  375. function GetAsLongint: Longint; override;
  376. function GetAsString: string; override;
  377. function GetAsVariant: variant; override;
  378. function GetDataSize: Word; override;
  379. function GetDefaultWidth: Longint; override;
  380. procedure GetText(var AText: string; ADisplayText: Boolean); override;
  381. function GetValue(var AValue: string): Boolean;
  382. procedure SetAsBoolean(AValue: Boolean); override;
  383. procedure SetAsDateTime(AValue: TDateTime); override;
  384. procedure SetAsFloat(AValue: Double); override;
  385. procedure SetAsLongint(AValue: Longint); override;
  386. procedure SetAsString(const AValue: string); override;
  387. procedure SetVarValue(const AValue: Variant); override;
  388. public
  389. constructor Create(AOwner: TComponent); override;
  390. property FixedChar : Boolean read FFixedChar write FFixedChar;
  391. property Transliterate: Boolean read FTransliterate write FTransliterate;
  392. published
  393. property Size default 20;
  394. end;
  395. { TNumericField }
  396. TNumericField = class(TField)
  397. Private
  398. FDisplayFormat : String;
  399. FEditFormat : String;
  400. protected
  401. procedure RangeError(AValue, Min, Max: Double);
  402. procedure SetDisplayFormat(const AValue: string);
  403. procedure SetEditFormat(const AValue: string);
  404. public
  405. constructor Create(AOwner: TComponent); override;
  406. published
  407. property DisplayFormat: string read FDisplayFormat write SetDisplayFormat;
  408. property EditFormat: string read FEditFormat write SetEditFormat;
  409. end;
  410. { TLongintField }
  411. TLongintField = class(TNumericField)
  412. private
  413. FMinValue,
  414. FMaxValue,
  415. FMinRange,
  416. FMAxRange : Longint;
  417. Procedure SetMinValue (AValue : longint);
  418. Procedure SetMaxValue (AValue : longint);
  419. protected
  420. function GetAsFloat: Double; override;
  421. function GetAsLongint: Longint; override;
  422. function GetAsString: string; override;
  423. function GetAsVariant: variant; override;
  424. function GetDataSize: Word; override;
  425. procedure GetText(var AText: string; ADisplayText: Boolean); override;
  426. function GetValue(var AValue: Longint): Boolean;
  427. procedure SetAsFloat(AValue: Double); override;
  428. procedure SetAsLongint(AValue: Longint); override;
  429. procedure SetAsString(const AValue: string); override;
  430. procedure SetVarValue(const AValue: Variant); override;
  431. public
  432. constructor Create(AOwner: TComponent); override;
  433. Function CheckRange(AValue : longint) : Boolean;
  434. property Value: Longint read GetAsLongint write SetAsLongint;
  435. published
  436. property MaxValue: Longint read FMaxValue write SetMaxValue default 0;
  437. property MinValue: Longint read FMinValue write SetMinValue default 0;
  438. end;
  439. TIntegerField = TLongintField;
  440. { TLargeintField }
  441. TLargeintField = class(TNumericField)
  442. private
  443. FMinValue,
  444. FMaxValue,
  445. FMinRange,
  446. FMAxRange : Largeint;
  447. Procedure SetMinValue (AValue : Largeint);
  448. Procedure SetMaxValue (AValue : Largeint);
  449. protected
  450. function GetAsFloat: Double; override;
  451. function GetAsLongint: Longint; override;
  452. function GetAsLargeint: Largeint; override;
  453. function GetAsString: string; override;
  454. function GetAsVariant: variant; override;
  455. function GetDataSize: Word; override;
  456. procedure GetText(var AText: string; ADisplayText: Boolean); override;
  457. function GetValue(var AValue: Largeint): Boolean;
  458. procedure SetAsFloat(AValue: Double); override;
  459. procedure SetAsLongint(AValue: Longint); override;
  460. procedure SetAsLargeint(AValue: Largeint); override;
  461. procedure SetAsString(const AValue: string); override;
  462. procedure SetVarValue(const AValue: Variant); override;
  463. public
  464. constructor Create(AOwner: TComponent); override;
  465. Function CheckRange(AValue : largeint) : Boolean;
  466. property Value: Longint read GetAsLongint write SetAsLongint;
  467. published
  468. property MaxValue: Largeint read FMaxValue write SetMaxValue default 0;
  469. property MinValue: Largeint read FMinValue write SetMinValue default 0;
  470. end;
  471. { TSmallintField }
  472. TSmallintField = class(TLongintField)
  473. protected
  474. function GetDataSize: Word; override;
  475. public
  476. constructor Create(AOwner: TComponent); override;
  477. end;
  478. { TWordField }
  479. TWordField = class(TLongintField)
  480. protected
  481. function GetDataSize: Word; override;
  482. public
  483. constructor Create(AOwner: TComponent); override;
  484. end;
  485. { TAutoIncField }
  486. TAutoIncField = class(TLongintField)
  487. Protected
  488. Procedure SetAsLongInt(AValue : Longint); override;
  489. public
  490. constructor Create(AOwner: TComponent); override;
  491. end;
  492. { TFloatField }
  493. TFloatField = class(TNumericField)
  494. private
  495. FMaxValue : Double;
  496. FMinValue : Double;
  497. FPrecision : Longint;
  498. protected
  499. function GetAsFloat: Double; override;
  500. function GetAsLongint: Longint; override;
  501. function GetAsVariant: variant; override;
  502. function GetAsString: string; override;
  503. function GetDataSize: Word; override;
  504. procedure GetText(var theText: string; ADisplayText: Boolean); override;
  505. procedure SetAsFloat(AValue: Double); override;
  506. procedure SetAsLongint(AValue: Longint); override;
  507. procedure SetAsString(const AValue: string); override;
  508. procedure SetVarValue(const AValue: Variant); override;
  509. public
  510. constructor Create(AOwner: TComponent); override;
  511. Function CheckRange(AValue : Double) : Boolean;
  512. property Value: Double read GetAsFloat write SetAsFloat;
  513. published
  514. property MaxValue: Double read FMaxValue write FMaxValue;
  515. property MinValue: Double read FMinValue write FMinValue;
  516. property Precision: Longint read FPrecision write FPrecision default 15;
  517. end;
  518. { TCurrencyField }
  519. TCurrencyField = class(TFloatField)
  520. public
  521. constructor Create(AOwner: TComponent); override;
  522. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  523. end;
  524. { TBooleanField }
  525. TBooleanField = class(TField)
  526. private
  527. FDisplayValues : String;
  528. // First byte indicates uppercase or not.
  529. FDisplays : Array[Boolean,Boolean] of string;
  530. Procedure SetDisplayValues(AValue : String);
  531. protected
  532. function GetAsBoolean: Boolean; override;
  533. function GetAsString: string; override;
  534. function GetAsVariant: variant; override;
  535. function GetDataSize: Word; override;
  536. function GetDefaultWidth: Longint; override;
  537. procedure SetAsBoolean(AValue: Boolean); override;
  538. procedure SetAsString(const AValue: string); override;
  539. procedure SetVarValue(const AValue: Variant); override;
  540. public
  541. constructor Create(AOwner: TComponent); override;
  542. property Value: Boolean read GetAsBoolean write SetAsBoolean;
  543. published
  544. property DisplayValues: string read FDisplayValues write SetDisplayValues;
  545. end;
  546. { TDateTimeField }
  547. TDateTimeField = class(TField)
  548. private
  549. FDisplayFormat : String;
  550. procedure SetDisplayFormat(const AValue: string);
  551. protected
  552. function GetAsDateTime: TDateTime; override;
  553. function GetAsFloat: Double; override;
  554. function GetAsString: string; override;
  555. function GetAsVariant: variant; override;
  556. function GetDataSize: Word; override;
  557. procedure GetText(var theText: string; ADisplayText: Boolean); override;
  558. procedure SetAsDateTime(AValue: TDateTime); override;
  559. procedure SetAsFloat(AValue: Double); override;
  560. procedure SetAsString(const AValue: string); override;
  561. procedure SetVarValue(const AValue: Variant); override;
  562. public
  563. constructor Create(AOwner: TComponent); override;
  564. property Value: TDateTime read GetAsDateTime write SetAsDateTime;
  565. published
  566. property DisplayFormat: string read FDisplayFormat write SetDisplayFormat;
  567. end;
  568. { TDateField }
  569. TDateField = class(TDateTimeField)
  570. public
  571. constructor Create(AOwner: TComponent); override;
  572. end;
  573. { TTimeField }
  574. TTimeField = class(TDateTimeField)
  575. protected
  576. procedure SetAsString(const AValue: string); override;
  577. public
  578. constructor Create(AOwner: TComponent); override;
  579. end;
  580. { TBinaryField }
  581. TBinaryField = class(TField)
  582. protected
  583. class procedure CheckTypeSize(AValue: Longint); override;
  584. function GetAsString: string; override;
  585. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  586. procedure SetAsString(const AValue: string); override;
  587. procedure SetText(const AValue: string); override;
  588. procedure SetVarValue(const AValue: Variant); override;
  589. public
  590. constructor Create(AOwner: TComponent); override;
  591. published
  592. property Size default 16;
  593. end;
  594. { TBytesField }
  595. TBytesField = class(TBinaryField)
  596. protected
  597. function GetDataSize: Word; override;
  598. public
  599. constructor Create(AOwner: TComponent); override;
  600. end;
  601. { TVarBytesField }
  602. TVarBytesField = class(TBytesField)
  603. protected
  604. function GetDataSize: Word; override;
  605. public
  606. constructor Create(AOwner: TComponent); override;
  607. end;
  608. { TBCDField }
  609. TBCDField = class(TNumericField)
  610. private
  611. FMinValue,
  612. FMaxValue : currency;
  613. FPrecision : Longint;
  614. FCurrency : boolean;
  615. protected
  616. class procedure CheckTypeSize(AValue: Longint); override;
  617. function GetAsCurrency: Currency; override;
  618. function GetAsFloat: Double; override;
  619. function GetAsLongint: Longint; override;
  620. function GetAsString: string; override;
  621. function GetValue(var AValue: Currency): Boolean;
  622. function GetAsVariant: variant; override;
  623. function GetDataSize: Word; override;
  624. function GetDefaultWidth: Longint; override;
  625. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  626. procedure SetAsFloat(AValue: Double); override;
  627. procedure SetAsLongint(AValue: Longint); override;
  628. procedure SetAsString(const AValue: string); override;
  629. procedure SetAsCurrency(AValue: Currency); override;
  630. procedure SetVarValue(const AValue: Variant); override;
  631. public
  632. constructor Create(AOwner: TComponent); override;
  633. Function CheckRange(AValue : Currency) : Boolean;
  634. property Value: Longint read GetAsLongint write SetAsLongint;
  635. published
  636. property Precision: Longint read FPrecision write FPrecision;
  637. property Currency: Boolean read FCurrency write FCurrency;
  638. property MaxValue: Currency read FMaxValue write FMaxValue;
  639. property MinValue: Currency read FMinValue write FMinValue;
  640. property Size default 4;
  641. end;
  642. { TBlobField }
  643. TBlobStreamMode = (bmRead, bmWrite, bmReadWrite);
  644. TBlobType = ftBlob..ftTypedBinary;
  645. TBlobField = class(TField)
  646. private
  647. FBlobSize : Longint;
  648. FBlobType : TBlobType;
  649. FModified : Boolean;
  650. FTransliterate : Boolean;
  651. Function GetBlobStream (Mode : TBlobStreamMode) : TStream;
  652. protected
  653. procedure AssignTo(Dest: TPersistent); override;
  654. procedure FreeBuffers; override;
  655. function GetAsString: string; override;
  656. function GetAsVariant: Variant; override;
  657. function GetBlobSize: Longint; virtual;
  658. function GetIsNull: Boolean; override;
  659. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  660. procedure SetAsString(const AValue: string); override;
  661. procedure SetText(const AValue: string); override;
  662. procedure SetVarValue(const AValue: Variant); override;
  663. public
  664. constructor Create(AOwner: TComponent); override;
  665. procedure Assign(Source: TPersistent); override;
  666. procedure Clear; override;
  667. class function IsBlob: Boolean; override;
  668. procedure LoadFromFile(const FileName: string);
  669. procedure LoadFromStream(Stream: TStream);
  670. procedure SaveToFile(const FileName: string);
  671. procedure SaveToStream(Stream: TStream);
  672. procedure SetFieldType(AValue: TFieldType); override;
  673. property BlobSize: Longint read FBlobSize;
  674. property Modified: Boolean read FModified write FModified;
  675. property Value: string read GetAsString write SetAsString;
  676. property Transliterate: Boolean read FTransliterate write FTransliterate;
  677. published
  678. property BlobType: TBlobType read FBlobType write FBlobType;
  679. property Size default 0;
  680. end;
  681. { TMemoField }
  682. TMemoField = class(TBlobField)
  683. public
  684. constructor Create(AOwner: TComponent); override;
  685. published
  686. property Transliterate default True;
  687. end;
  688. { TGraphicField }
  689. TGraphicField = class(TBlobField)
  690. public
  691. constructor Create(AOwner: TComponent); override;
  692. end;
  693. { TIndexDef }
  694. TIndexDefs = class;
  695. TIndexOption = (ixPrimary, ixUnique, ixDescending, ixCaseInsensitive,
  696. ixExpression, ixNonMaintained);
  697. TIndexOptions = set of TIndexOption;
  698. TIndexDef = class(TCollectionItem)
  699. Private
  700. FCaseinsFields: string;
  701. FDescFields: string;
  702. FExpression : String;
  703. FFields : String;
  704. FName : String;
  705. FOptions : TIndexOptions;
  706. FSource : String;
  707. protected
  708. procedure SetCaseInsFields(const AValue: string); virtual;
  709. procedure SetDescFields(const AValue: string);
  710. public
  711. constructor Create(Owner: TIndexDefs; const AName, TheFields: string;
  712. TheOptions: TIndexOptions); overload;
  713. destructor Destroy; override;
  714. property Expression: string read FExpression;
  715. property Fields: string read FFields write FFields;
  716. property CaseInsFields: string read FCaseinsFields write SetCaseInsFields;
  717. property DescFields: string read FDescFields write SetDescFields;
  718. property Name: string read FName write FName;
  719. property Options: TIndexOptions read FOptions write FOptions;
  720. property Source: string read FSource write FSource;
  721. end;
  722. { TIndexDefs }
  723. TIndexDefs = class(TOwnedCollection)
  724. Private
  725. FUpDated : Boolean;
  726. FDataset : Tdataset;
  727. Function GetItem(Index: Integer): TIndexDef;
  728. Procedure SetItem(Index: Integer; Value: TIndexDef);
  729. public
  730. constructor Create(DataSet: TDataSet); overload;
  731. destructor Destroy; override;
  732. procedure Add(const Name, Fields: string; Options: TIndexOptions);
  733. Function AddIndexDef: TIndexDef;
  734. procedure Assign(IndexDefs: TIndexDefs); overload;
  735. // procedure Clear;
  736. function Find(const IndexName: string): TIndexDef;
  737. function FindIndexForFields(const Fields: string): TIndexDef;
  738. function GetIndexForFields(const Fields: string;
  739. CaseInsensitive: Boolean): TIndexDef;
  740. function IndexOf(const Name: string): Longint;
  741. procedure Update; overload;
  742. // property Count: Longint read FCount;
  743. Property Items[Index: Integer] : TIndexDef read GetItem write SetItem; default;
  744. property Updated: Boolean read FUpdated write FUpdated;
  745. end;
  746. { TCheckConstraint }
  747. TCheckConstraint = class(TCollectionItem)
  748. Private
  749. FCustomConstraint : String;
  750. FErrorMessage : String;
  751. FFromDictionary : Boolean;
  752. FImportedConstraint : String;
  753. public
  754. procedure Assign(Source: TPersistent); override;
  755. // function GetDisplayName: string; override;
  756. published
  757. property CustomConstraint: string read FCustomConstraint write FCustomConstraint;
  758. property ErrorMessage: string read FErrorMessage write FErrorMessage;
  759. property FromDictionary: Boolean read FFromDictionary write FFromDictionary;
  760. property ImportedConstraint: string read FImportedConstraint write FImportedConstraint;
  761. end;
  762. { TCheckConstraints }
  763. TCheckConstraints = class(TCollection)
  764. Private
  765. Function GetItem(Index : Longint) : TCheckConstraint;
  766. Procedure SetItem(index : Longint; Value : TCheckConstraint);
  767. protected
  768. function GetOwner: TPersistent; override;
  769. public
  770. constructor Create(AOwner: TPersistent);
  771. function Add: TCheckConstraint;
  772. property Items[Index: Longint]: TCheckConstraint read GetItem write SetItem; default;
  773. end;
  774. { TFields }
  775. Tfields = Class(TObject)
  776. Private
  777. FDataset : TDataset;
  778. FFieldList : TList;
  779. FOnChange : TNotifyEvent;
  780. FValidFieldKinds : TFieldKinds;
  781. Protected
  782. Procedure Changed;
  783. Procedure CheckfieldKind(Fieldkind : TFieldKind; Field : TField);
  784. Function GetCount : Longint;
  785. Function GetField (Index : longint) : TField;
  786. Procedure SetField(Index: Integer; Value: TField);
  787. Procedure SetFieldIndex (Field : TField;Value : Integer);
  788. Property OnChange : TNotifyEvent Read FOnChange Write FOnChange;
  789. Property ValidFieldKinds : TFieldKinds Read FValidFieldKinds;
  790. Public
  791. Constructor Create(ADataset : TDataset);
  792. Destructor Destroy;override;
  793. Procedure Add(Field : TField);
  794. Procedure CheckFieldName (Const Value : String);
  795. Procedure CheckFieldNames (Const Value : String);
  796. Procedure Clear;
  797. Function FindField (Const Value : String) : TField;
  798. Function FieldByName (Const Value : String) : TField;
  799. Function FieldByNumber(FieldNo : Integer) : TField;
  800. Procedure GetFieldNames (Values : TStrings);
  801. Function IndexOf(Field : TField) : Longint;
  802. procedure Remove(Value : TField);
  803. Property Count : Integer Read GetCount;
  804. Property Dataset : TDataset Read FDataset;
  805. Property Fields [Index : Integer] : TField Read GetField Write SetField; default;
  806. end;
  807. { TDataSet }
  808. TBookmark = Pointer;
  809. TBookmarkStr = string;
  810. PBookmarkFlag = ^TBookmarkFlag;
  811. TBookmarkFlag = (bfCurrent, bfBOF, bfEOF, bfInserted);
  812. PBufferList = ^TBufferList;
  813. TBufferList = array[0..dsMaxBufferCount - 1] of PChar;
  814. TGetMode = (gmCurrent, gmNext, gmPrior);
  815. TGetResult = (grOK, grBOF, grEOF, grError);
  816. TResyncMode = set of (rmExact, rmCenter);
  817. TDataAction = (daFail, daAbort, daRetry);
  818. TUpdateAction = (uaFail, uaAbort, uaSkip, uaRetry, uaApplied);
  819. TUpdateKind = (ukModify, ukInsert, ukDelete);
  820. TLocateOption = (loCaseInsensitive, loPartialKey);
  821. TLocateOptions = set of TLocateOption;
  822. TDataOperation = procedure of object;
  823. TDataSetNotifyEvent = procedure(DataSet: TDataSet) of object;
  824. TDataSetErrorEvent = procedure(DataSet: TDataSet; E: EDatabaseError;
  825. var DataAction: TDataAction) of object;
  826. TFilterOption = (foCaseInsensitive, foNoPartialCompare);
  827. TFilterOptions = set of TFilterOption;
  828. TFilterRecordEvent = procedure(DataSet: TDataSet;
  829. var Accept: Boolean) of object;
  830. TDatasetClass = Class of TDataset;
  831. TBufferArray = ^pchar;
  832. TDataSet = class(TComponent)
  833. Private
  834. FOpenAfterRead : boolean;
  835. FActiveRecord: Longint;
  836. FAfterCancel: TDataSetNotifyEvent;
  837. FAfterClose: TDataSetNotifyEvent;
  838. FAfterDelete: TDataSetNotifyEvent;
  839. FAfterEdit: TDataSetNotifyEvent;
  840. FAfterInsert: TDataSetNotifyEvent;
  841. FAfterOpen: TDataSetNotifyEvent;
  842. FAfterPost: TDataSetNotifyEvent;
  843. FAfterRefresh: TDataSetNotifyEvent;
  844. FAfterScroll: TDataSetNotifyEvent;
  845. FAutoCalcFields: Boolean;
  846. FBOF: Boolean;
  847. FBeforeCancel: TDataSetNotifyEvent;
  848. FBeforeClose: TDataSetNotifyEvent;
  849. FBeforeDelete: TDataSetNotifyEvent;
  850. FBeforeEdit: TDataSetNotifyEvent;
  851. FBeforeInsert: TDataSetNotifyEvent;
  852. FBeforeOpen: TDataSetNotifyEvent;
  853. FBeforePost: TDataSetNotifyEvent;
  854. FBeforeRefresh: TDataSetNotifyEvent;
  855. FBeforeScroll: TDataSetNotifyEvent;
  856. FBlobFieldCount: Longint;
  857. FBookmarkSize: Longint;
  858. FBuffers : TBufferArray;
  859. FBufferCount: Longint;
  860. FCalcBuffer: PChar;
  861. FCalcFieldsSize: Longint;
  862. FConstraints: TCheckConstraints;
  863. FDisableControlsCount : Integer;
  864. FDisableControlsState : TDatasetState;
  865. FCurrentRecord: Longint;
  866. FDataSources : TList;
  867. FDefaultFields: Boolean;
  868. FEOF: Boolean;
  869. FEnableControlsEvent : TDataEvent;
  870. FFieldList : TFields;
  871. FFieldDefs: TFieldDefs;
  872. FFilterOptions: TFilterOptions;
  873. FFilterText: string;
  874. FFiltered: Boolean;
  875. FFound: Boolean;
  876. FInternalCalcFields: Boolean;
  877. FModified: Boolean;
  878. FOnCalcFields: TDataSetNotifyEvent;
  879. FOnDeleteError: TDataSetErrorEvent;
  880. FOnEditError: TDataSetErrorEvent;
  881. FOnFilterRecord: TFilterRecordEvent;
  882. FOnNewRecord: TDataSetNotifyEvent;
  883. FOnPostError: TDataSetErrorEvent;
  884. FRecordCount: Longint;
  885. FIsUniDirectional: Boolean;
  886. FState : TDataSetState;
  887. FInternalOpenComplete: Boolean;
  888. Procedure DoInsertAppend(DoAppend : Boolean);
  889. Procedure DoInternalOpen;
  890. Function GetBuffer (Index : longint) : Pchar;
  891. Function GetField (Index : Longint) : TField;
  892. Procedure RegisterDataSource(ADatasource : TDataSource);
  893. Procedure RemoveField (Field : TField);
  894. Procedure SetField (Index : Longint;Value : TField);
  895. Procedure ShiftBuffersForward;
  896. Procedure ShiftBuffersBackward;
  897. Function TryDoing (P : TDataOperation; Ev : TDatasetErrorEvent) : Boolean;
  898. Function GetActive : boolean;
  899. Procedure UnRegisterDataSource(ADatasource : TDatasource);
  900. Procedure UpdateFieldDefs;
  901. protected
  902. procedure RecalcBufListSize;
  903. procedure ActivateBuffers; virtual;
  904. procedure BindFields(Binding: Boolean);
  905. function BookmarkAvailable: Boolean;
  906. procedure CalculateFields(Buffer: PChar); virtual;
  907. procedure CheckActive; virtual;
  908. procedure CheckInactive; virtual;
  909. procedure CheckBiDirectional;
  910. procedure Loaded; override;
  911. procedure ClearBuffers; virtual;
  912. procedure ClearCalcFields(Buffer: PChar); virtual;
  913. procedure CloseBlob(Field: TField); virtual;
  914. procedure CloseCursor; virtual;
  915. procedure CreateFields; virtual;
  916. procedure DataEvent(Event: TDataEvent; Info: Ptrint); virtual;
  917. procedure DestroyFields; virtual;
  918. procedure DoAfterCancel; virtual;
  919. procedure DoAfterClose; virtual;
  920. procedure DoAfterDelete; virtual;
  921. procedure DoAfterEdit; virtual;
  922. procedure DoAfterInsert; virtual;
  923. procedure DoAfterOpen; virtual;
  924. procedure DoAfterPost; virtual;
  925. procedure DoAfterScroll; virtual;
  926. procedure DoAfterRefresh; virtual;
  927. procedure DoBeforeCancel; virtual;
  928. procedure DoBeforeClose; virtual;
  929. procedure DoBeforeDelete; virtual;
  930. procedure DoBeforeEdit; virtual;
  931. procedure DoBeforeInsert; virtual;
  932. procedure DoBeforeOpen; virtual;
  933. procedure DoBeforePost; virtual;
  934. procedure DoBeforeScroll; virtual;
  935. procedure DoBeforeRefresh; virtual;
  936. procedure DoOnCalcFields; virtual;
  937. procedure DoOnNewRecord; virtual;
  938. function FieldByNumber(FieldNo: Longint): TField;
  939. function FindRecord(Restart, GoForward: Boolean): Boolean; virtual;
  940. procedure FreeFieldBuffers; virtual;
  941. function GetBookmarkStr: TBookmarkStr; virtual;
  942. procedure GetCalcFields(Buffer: PChar); virtual;
  943. function GetCanModify: Boolean; virtual;
  944. procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
  945. function GetFieldClass(FieldType: TFieldType): TFieldClass; virtual;
  946. Function GetfieldCount : Integer;
  947. function GetFieldValues(fieldname : string) : Variant; virtual;
  948. function GetIsIndexField(Field: TField): Boolean; virtual;
  949. function GetNextRecords: Longint; virtual;
  950. function GetNextRecord: Boolean; virtual;
  951. function GetPriorRecords: Longint; virtual;
  952. function GetPriorRecord: Boolean; virtual;
  953. function GetRecordCount: Longint; virtual;
  954. function GetRecNo: Longint; virtual;
  955. procedure InitFieldDefs; virtual;
  956. procedure InitRecord(Buffer: PChar); virtual;
  957. procedure InternalCancel; virtual;
  958. procedure InternalEdit; virtual;
  959. procedure InternalInsert; virtual;
  960. procedure InternalRefresh; virtual;
  961. procedure OpenCursor(InfoQuery: Boolean); virtual;
  962. procedure OpenCursorcomplete; virtual;
  963. procedure RefreshInternalCalcFields(Buffer: PChar); virtual;
  964. procedure RestoreState(const Value: TDataSetState);
  965. Procedure SetActive (Value : Boolean); virtual;
  966. procedure SetBookmarkStr(const Value: TBookmarkStr); virtual;
  967. procedure SetBufListSize(Value: Longint); virtual;
  968. procedure SetChildOrder(Component: TComponent; Order: Longint); override;
  969. procedure SetCurrentRecord(Index: Longint); virtual;
  970. procedure SetFiltered(Value: Boolean); virtual;
  971. procedure SetFilterOptions(Value: TFilterOptions); virtual;
  972. procedure SetFilterText(const Value: string); virtual;
  973. procedure SetFound(const Value: Boolean);
  974. procedure SetFieldValues(fieldname: string; Value: Variant); virtual;
  975. procedure SetModified(Value: Boolean);
  976. procedure SetName(const Value: TComponentName); override;
  977. procedure SetOnFilterRecord(const Value: TFilterRecordEvent); virtual;
  978. procedure SetRecNo(Value: Longint); virtual;
  979. procedure SetState(Value: TDataSetState);
  980. function SetTempState(const Value: TDataSetState): TDataSetState;
  981. Function Tempbuffer: PChar;
  982. procedure UpdateIndexDefs; virtual;
  983. property ActiveRecord: Longint read FActiveRecord;
  984. property CurrentRecord: Longint read FCurrentRecord;
  985. property BlobFieldCount: Longint read FBlobFieldCount;
  986. property BookmarkSize: Longint read FBookmarkSize write FBookmarkSize;
  987. property Buffers[Index: Longint]: PChar read GetBuffer;
  988. property BufferCount: Longint read FBufferCount;
  989. property CalcBuffer: PChar read FCalcBuffer;
  990. property CalcFieldsSize: Longint read FCalcFieldsSize;
  991. property InternalCalcFields: Boolean read FInternalCalcFields;
  992. property Constraints: TCheckConstraints read FConstraints write FConstraints;
  993. protected { abstract methods }
  994. function AllocRecordBuffer: PChar; virtual; abstract;
  995. procedure FreeRecordBuffer(var Buffer: PChar); virtual; abstract;
  996. procedure GetBookmarkData(Buffer: PChar; Data: Pointer); virtual; abstract;
  997. function GetBookmarkFlag(Buffer: PChar): TBookmarkFlag; virtual; abstract;
  998. function GetDataSource: TDataSource; virtual;
  999. function GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck: Boolean): TGetResult; virtual; abstract;
  1000. function GetRecordSize: Word; virtual; abstract;
  1001. procedure InternalAddRecord(Buffer: Pointer; AAppend: Boolean); virtual; abstract;
  1002. procedure InternalClose; virtual; abstract;
  1003. procedure InternalDelete; virtual; abstract;
  1004. procedure InternalFirst; virtual; abstract;
  1005. procedure InternalGotoBookmark(ABookmark: Pointer); virtual; abstract;
  1006. procedure InternalHandleException; virtual;
  1007. procedure InternalInitFieldDefs; virtual; abstract;
  1008. procedure InternalInitRecord(Buffer: PChar); virtual; abstract;
  1009. procedure InternalLast; virtual; abstract;
  1010. procedure InternalOpen; virtual; abstract;
  1011. procedure InternalPost; virtual; abstract;
  1012. procedure InternalSetToRecord(Buffer: PChar); virtual; abstract;
  1013. function IsCursorOpen: Boolean; virtual; abstract;
  1014. procedure SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag); virtual; abstract;
  1015. procedure SetBookmarkData(Buffer: PChar; Data: Pointer); virtual; abstract;
  1016. procedure SetUniDirectional(const Value: Boolean);
  1017. public
  1018. constructor Create(AOwner: TComponent); override;
  1019. destructor Destroy; override;
  1020. function ActiveBuffer: PChar;
  1021. function GetFieldData(Field: TField; Buffer: Pointer): Boolean; overload; virtual;
  1022. function GetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean): Boolean; overload; virtual;
  1023. procedure SetFieldData(Field: TField; Buffer: Pointer); overload; virtual;
  1024. procedure SetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean); overload; virtual;
  1025. procedure Append;
  1026. procedure AppendRecord(const Values: array of const);
  1027. function BookmarkValid(ABookmark: TBookmark): Boolean; virtual;
  1028. procedure Cancel; virtual;
  1029. procedure CheckBrowseMode;
  1030. procedure ClearFields;
  1031. procedure Close;
  1032. function ControlsDisabled: Boolean;
  1033. function CompareBookmarks(Bookmark1, Bookmark2: TBookmark): Longint; virtual;
  1034. function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; virtual;
  1035. procedure CursorPosChanged;
  1036. procedure DataConvert(aField: TField; aSource, aDest: Pointer; aToNative: Boolean); virtual;
  1037. procedure Delete;
  1038. procedure DisableControls;
  1039. procedure Edit;
  1040. procedure EnableControls;
  1041. function FieldByName(const FieldName: string): TField;
  1042. function FindField(const FieldName: string): TField;
  1043. function FindFirst: Boolean;
  1044. function FindLast: Boolean;
  1045. function FindNext: Boolean;
  1046. function FindPrior: Boolean;
  1047. procedure First;
  1048. procedure FreeBookmark(ABookmark: TBookmark); virtual;
  1049. function GetBookmark: TBookmark; virtual;
  1050. function GetCurrentRecord(Buffer: PChar): Boolean; virtual;
  1051. procedure GetFieldList(List: TList; const FieldNames: string);
  1052. procedure GetFieldNames(List: TStrings);
  1053. procedure GotoBookmark(ABookmark: TBookmark);
  1054. procedure Insert;
  1055. procedure InsertRecord(const Values: array of const);
  1056. function IsEmpty: Boolean;
  1057. function IsLinkedTo(ADataSource: TDataSource): Boolean;
  1058. function IsSequenced: Boolean; virtual;
  1059. procedure Last;
  1060. function Locate(const keyfields: string; const keyvalues: Variant; options: TLocateOptions) : boolean; virtual;
  1061. function Lookup(const KeyFields: string; const KeyValues: Variant; const ResultFields: string): Variant; virtual;
  1062. function MoveBy(Distance: Longint): Longint;
  1063. procedure Next;
  1064. procedure Open;
  1065. procedure Post; virtual;
  1066. procedure Prior;
  1067. procedure Refresh;
  1068. procedure Resync(Mode: TResyncMode); virtual;
  1069. procedure SetFields(const Values: array of const);
  1070. function Translate(Src, Dest: PChar; ToOem: Boolean): Integer; virtual;
  1071. procedure UpdateCursorPos;
  1072. procedure UpdateRecord;
  1073. function UpdateStatus: TUpdateStatus; virtual;
  1074. property BOF: Boolean read FBOF;
  1075. property Bookmark: TBookmarkStr read GetBookmarkStr write SetBookmarkStr;
  1076. property CanModify: Boolean read GetCanModify;
  1077. property DataSource: TDataSource read GetDataSource;
  1078. property DefaultFields: Boolean read FDefaultFields;
  1079. property EOF: Boolean read FEOF;
  1080. property FieldCount: Longint read GetFieldCount;
  1081. property FieldDefs: TFieldDefs read FFieldDefs write FFieldDefs;
  1082. // property Fields[Index: Longint]: TField read GetField write SetField;
  1083. property Found: Boolean read FFound;
  1084. property Modified: Boolean read FModified write SetModified;
  1085. property IsUniDirectional: Boolean read FIsUniDirectional default False;
  1086. property RecordCount: Longint read GetRecordCount;
  1087. property RecNo: Longint read GetRecNo write SetRecNo;
  1088. property RecordSize: Word read GetRecordSize;
  1089. property State: TDataSetState read FState;
  1090. property Fields : TFields read FFieldList;
  1091. property FieldValues[fieldname : string] : Variant read GetFieldValues write SetFieldValues; default;
  1092. property Filter: string read FFilterText write SetFilterText;
  1093. property Filtered: Boolean read FFiltered write SetFiltered default False;
  1094. property FilterOptions: TFilterOptions read FFilterOptions write SetFilterOptions;
  1095. property Active: Boolean read GetActive write SetActive default False;
  1096. property AutoCalcFields: Boolean read FAutoCalcFields write FAutoCalcFields;
  1097. property BeforeOpen: TDataSetNotifyEvent read FBeforeOpen write FBeforeOpen;
  1098. property AfterOpen: TDataSetNotifyEvent read FAfterOpen write FAfterOpen;
  1099. property BeforeClose: TDataSetNotifyEvent read FBeforeClose write FBeforeClose;
  1100. property AfterClose: TDataSetNotifyEvent read FAfterClose write FAfterClose;
  1101. property BeforeInsert: TDataSetNotifyEvent read FBeforeInsert write FBeforeInsert;
  1102. property AfterInsert: TDataSetNotifyEvent read FAfterInsert write FAfterInsert;
  1103. property BeforeEdit: TDataSetNotifyEvent read FBeforeEdit write FBeforeEdit;
  1104. property AfterEdit: TDataSetNotifyEvent read FAfterEdit write FAfterEdit;
  1105. property BeforePost: TDataSetNotifyEvent read FBeforePost write FBeforePost;
  1106. property AfterPost: TDataSetNotifyEvent read FAfterPost write FAfterPost;
  1107. property BeforeCancel: TDataSetNotifyEvent read FBeforeCancel write FBeforeCancel;
  1108. property AfterCancel: TDataSetNotifyEvent read FAfterCancel write FAfterCancel;
  1109. property BeforeDelete: TDataSetNotifyEvent read FBeforeDelete write FBeforeDelete;
  1110. property AfterDelete: TDataSetNotifyEvent read FAfterDelete write FAfterDelete;
  1111. property BeforeScroll: TDataSetNotifyEvent read FBeforeScroll write FBeforeScroll;
  1112. property AfterScroll: TDataSetNotifyEvent read FAfterScroll write FAfterScroll;
  1113. property BeforeRefresh: TDataSetNotifyEvent read FBeforeRefresh write FBeforeRefresh;
  1114. property AfterRefresh: TDataSetNotifyEvent read FAfterRefresh write FAfterRefresh;
  1115. property OnCalcFields: TDataSetNotifyEvent read FOnCalcFields write FOnCalcFields;
  1116. property OnDeleteError: TDataSetErrorEvent read FOnDeleteError write FOnDeleteError;
  1117. property OnEditError: TDataSetErrorEvent read FOnEditError write FOnEditError;
  1118. property OnFilterRecord: TFilterRecordEvent read FOnFilterRecord write SetOnFilterRecord;
  1119. property OnNewRecord: TDataSetNotifyEvent read FOnNewRecord write FOnNewRecord;
  1120. property OnPostError: TDataSetErrorEvent read FOnPostError write FOnPostError;
  1121. end;
  1122. TDataLink = class(TPersistent)
  1123. private
  1124. FFirstRecord,
  1125. FBufferCount : Integer;
  1126. FActive,
  1127. FDataSourceFixed,
  1128. FEditing,
  1129. FReadOnly,
  1130. FUpdatingRecord,
  1131. FVisualControl : Boolean;
  1132. FDataSource : TDataSource;
  1133. Function CalcFirstRecord(Index : Integer) : Integer;
  1134. Procedure CalcRange;
  1135. Procedure CheckActiveAndEditing;
  1136. Function GetDataset : TDataset;
  1137. procedure SetActive(AActive: Boolean);
  1138. procedure SetDataSource(Value: TDataSource);
  1139. Procedure SetReadOnly(Value : Boolean);
  1140. protected
  1141. procedure ActiveChanged; virtual;
  1142. procedure CheckBrowseMode; virtual;
  1143. procedure DataEvent(Event: TDataEvent; Info: Ptrint); virtual;
  1144. procedure DataSetChanged; virtual;
  1145. procedure DataSetScrolled(Distance: Integer); virtual;
  1146. procedure EditingChanged; virtual;
  1147. procedure FocusControl(Field: TFieldRef); virtual;
  1148. function GetActiveRecord: Integer; virtual;
  1149. function GetBOF: Boolean; virtual;
  1150. function GetBufferCount: Integer; virtual;
  1151. function GetEOF: Boolean; virtual;
  1152. function GetRecordCount: Integer; virtual;
  1153. procedure LayoutChanged; virtual;
  1154. function MoveBy(Distance: Integer): Integer; virtual;
  1155. procedure RecordChanged(Field: TField); virtual;
  1156. procedure SetActiveRecord(Value: Integer); virtual;
  1157. procedure SetBufferCount(Value: Integer); virtual;
  1158. procedure UpdateData; virtual;
  1159. property VisualControl: Boolean read FVisualControl write FVisualControl;
  1160. property FirstRecord: Integer read FFirstRecord write FFirstRecord;
  1161. public
  1162. constructor Create;
  1163. destructor Destroy; override;
  1164. function Edit: Boolean;
  1165. procedure UpdateRecord;
  1166. property Active: Boolean read FActive;
  1167. property ActiveRecord: Integer read GetActiveRecord write SetActiveRecord;
  1168. property BOF: Boolean read GetBOF;
  1169. property BufferCount: Integer read FBufferCount write SetBufferCount;
  1170. property DataSet: TDataSet read GetDataSet;
  1171. property DataSource: TDataSource read FDataSource write SetDataSource;
  1172. property DataSourceFixed: Boolean read FDataSourceFixed write FDataSourceFixed;
  1173. property Editing: Boolean read FEditing;
  1174. property Eof: Boolean read GetEOF;
  1175. property ReadOnly: Boolean read FReadOnly write SetReadOnly;
  1176. property RecordCount: Integer read GetRecordCount;
  1177. end;
  1178. { TDetailDataLink }
  1179. TDetailDataLink = class(TDataLink)
  1180. protected
  1181. function GetDetailDataSet: TDataSet; virtual;
  1182. public
  1183. property DetailDataSet: TDataSet read GetDetailDataSet;
  1184. end;
  1185. { TMasterDataLink }
  1186. TMasterDataLink = class(TDetailDataLink)
  1187. private
  1188. FDetailDataSet: TDataSet;
  1189. FFieldNames: string;
  1190. FFields: TList;
  1191. FOnMasterChange: TNotifyEvent;
  1192. FOnMasterDisable: TNotifyEvent;
  1193. procedure SetFieldNames(const Value: string);
  1194. protected
  1195. procedure ActiveChanged; override;
  1196. procedure CheckBrowseMode; override;
  1197. function GetDetailDataSet: TDataSet; override;
  1198. procedure LayoutChanged; override;
  1199. procedure RecordChanged(Field: TField); override;
  1200. Procedure DoMasterDisable; virtual;
  1201. Procedure DoMasterChange; virtual;
  1202. public
  1203. constructor Create(ADataSet: TDataSet);virtual;
  1204. destructor Destroy; override;
  1205. property FieldNames: string read FFieldNames write SetFieldNames;
  1206. property Fields: TList read FFields;
  1207. property OnMasterChange: TNotifyEvent read FOnMasterChange write FOnMasterChange;
  1208. property OnMasterDisable: TNotifyEvent read FOnMasterDisable write FOnMasterDisable;
  1209. end;
  1210. { TDataSource }
  1211. TDataChangeEvent = procedure(Sender: TObject; Field: TField) of object;
  1212. TDataSource = class(TComponent)
  1213. private
  1214. FDataSet: TDataSet;
  1215. FDataLinks: TList;
  1216. FEnabled: Boolean;
  1217. FAutoEdit: Boolean;
  1218. FState: TDataSetState;
  1219. FOnStateChange: TNotifyEvent;
  1220. FOnDataChange: TDataChangeEvent;
  1221. FOnUpdateData: TNotifyEvent;
  1222. procedure DistributeEvent(Event: TDataEvent; Info: Ptrint);
  1223. procedure RegisterDataLink(DataLink: TDataLink);
  1224. Procedure ProcessEvent(Event : TDataEvent; Info : Ptrint);
  1225. procedure SetDataSet(ADataSet: TDataSet);
  1226. procedure SetEnabled(Value: Boolean);
  1227. procedure UnregisterDataLink(DataLink: TDataLink);
  1228. protected
  1229. Procedure DoDataChange (Info : Pointer);virtual;
  1230. Procedure DoStateChange; virtual;
  1231. Procedure DoUpdateData;
  1232. property DataLinks: TList read FDataLinks;
  1233. public
  1234. constructor Create(AOwner: TComponent); override;
  1235. destructor Destroy; override;
  1236. procedure Edit;
  1237. function IsLinkedTo(ADataSet: TDataSet): Boolean;
  1238. property State: TDataSetState read FState;
  1239. published
  1240. property AutoEdit: Boolean read FAutoEdit write FAutoEdit default True;
  1241. property DataSet: TDataSet read FDataSet write SetDataSet;
  1242. property Enabled: Boolean read FEnabled write SetEnabled default True;
  1243. property OnStateChange: TNotifyEvent read FOnStateChange write FOnStateChange;
  1244. property OnDataChange: TDataChangeEvent read FOnDataChange write FOnDataChange;
  1245. property OnUpdateData: TNotifyEvent read FOnUpdateData write FOnUpdateData;
  1246. end;
  1247. { TDBDataset }
  1248. TDBDatasetClass = Class of TDBDataset;
  1249. TDBDataset = Class(TDataset)
  1250. Private
  1251. FDatabase : TDatabase;
  1252. FTransaction : TDBTransaction;
  1253. Protected
  1254. Procedure SetDatabase (Value : TDatabase); virtual;
  1255. Procedure SetTransaction(Value : TDBTransaction); virtual;
  1256. Procedure CheckDatabase;
  1257. Public
  1258. Destructor destroy; override;
  1259. Property DataBase : TDatabase Read FDatabase Write SetDatabase;
  1260. Property Transaction : TDBTransaction Read FTransaction Write SetTransaction;
  1261. end;
  1262. { TDBTransaction }
  1263. TDBTransactionClass = Class of TDBTransaction;
  1264. TDBTransaction = Class(TComponent)
  1265. Private
  1266. FActive : boolean;
  1267. FDatabase : TDatabase;
  1268. FDataSets : TList;
  1269. FOpenAfterRead : boolean;
  1270. Function GetDataSetCount : Longint;
  1271. Function GetDataset(Index : longint) : TDBDataset;
  1272. procedure RegisterDataset (DS : TDBDataset);
  1273. procedure UnRegisterDataset (DS : TDBDataset);
  1274. procedure RemoveDataSets;
  1275. procedure SetActive(Value : boolean);
  1276. Protected
  1277. Procedure SetDatabase (Value : TDatabase); virtual;
  1278. procedure CloseTrans;
  1279. procedure openTrans;
  1280. Procedure CheckDatabase;
  1281. Procedure CheckActive;
  1282. Procedure CheckInactive;
  1283. procedure EndTransaction; virtual; abstract;
  1284. procedure StartTransaction; virtual; abstract;
  1285. procedure InternalHandleException; virtual;
  1286. procedure Loaded; override;
  1287. Public
  1288. constructor Create(AOwner: TComponent); override;
  1289. Destructor destroy; override;
  1290. procedure CloseDataSets;
  1291. Property DataBase : TDatabase Read FDatabase Write SetDatabase;
  1292. published
  1293. property Active : boolean read FActive write setactive;
  1294. end;
  1295. { TDatabase }
  1296. TLoginEvent = procedure(Sender: TObject; Username, Password: string) of object;
  1297. TDatabaseClass = Class Of TDatabase;
  1298. TDatabase = class(TComponent)
  1299. private
  1300. FConnected : Boolean;
  1301. FDataBaseName : String;
  1302. FDataSets : TList;
  1303. FTransactions : TList;
  1304. FDirectory : String;
  1305. FKeepConnection : Boolean;
  1306. FLoginPrompt : Boolean;
  1307. FOnLogin : TLoginEvent;
  1308. FParams : TStrings;
  1309. FSQLBased : Boolean;
  1310. FOpenAfterRead : boolean;
  1311. Function GetDataSetCount : Longint;
  1312. Function GetTransactionCount : Longint;
  1313. Function GetDataset(Index : longint) : TDBDataset;
  1314. Function GetTransaction(Index : longint) : TDBTransaction;
  1315. procedure SetConnected (Value : boolean);
  1316. procedure RegisterDataset (DS : TDBDataset);
  1317. procedure RegisterTransaction (TA : TDBTransaction);
  1318. procedure UnRegisterDataset (DS : TDBDataset);
  1319. procedure UnRegisterTransaction(TA : TDBTransaction);
  1320. procedure RemoveDataSets;
  1321. procedure RemoveTransactions;
  1322. protected
  1323. Procedure CheckConnected;
  1324. Procedure CheckDisConnected;
  1325. procedure InternalHandleException; virtual;
  1326. procedure Loaded; override;
  1327. Procedure DoInternalConnect; Virtual;Abstract;
  1328. Procedure DoInternalDisConnect; Virtual;Abstract;
  1329. public
  1330. constructor Create(AOwner: TComponent); override;
  1331. destructor Destroy; override;
  1332. procedure Close;
  1333. procedure Open;
  1334. procedure CloseDataSets;
  1335. procedure CloseTransactions;
  1336. // procedure ApplyUpdates;
  1337. procedure StartTransaction; virtual; abstract;
  1338. procedure EndTransaction; virtual; abstract;
  1339. property DataSetCount: Longint read GetDataSetCount;
  1340. property DataSets[Index: Longint]: TDBDataSet read GetDataSet;
  1341. property TransactionCount: Longint read GetTransactionCount;
  1342. property Transactions[Index: Longint]: TDBTransaction read GetTransaction;
  1343. property Directory: string read FDirectory write FDirectory;
  1344. property IsSQLBased: Boolean read FSQLBased;
  1345. published
  1346. property Connected: Boolean read FConnected write SetConnected;
  1347. property DatabaseName: string read FDatabaseName write FDatabaseName;
  1348. property KeepConnection: Boolean read FKeepConnection write FKeepConnection;
  1349. property LoginPrompt: Boolean read FLoginPrompt write FLoginPrompt;
  1350. property Params : TStrings read FParams Write FParams;
  1351. property OnLogin: TLoginEvent read FOnLogin write FOnLogin;
  1352. end;
  1353. { TCustomConnection }
  1354. TCustomConnection = class(TDatabase)
  1355. private
  1356. FAfterConnect: TNotifyEvent;
  1357. FAfterDisconnect: TNotifyEvent;
  1358. FBeforeConnect: TNotifyEvent;
  1359. FBeforeDisconnect: TNotifyEvent;
  1360. procedure SetAfterConnect(const AValue: TNotifyEvent);
  1361. procedure SetAfterDisconnect(const AValue: TNotifyEvent);
  1362. procedure SetBeforeConnect(const AValue: TNotifyEvent);
  1363. procedure SetBeforeDisconnect(const AValue: TNotifyEvent);
  1364. protected
  1365. procedure DoInternalConnect; override;
  1366. procedure DoInternalDisconnect; override;
  1367. procedure DoConnect; virtual;
  1368. procedure DoDisconnect; virtual;
  1369. function GetConnected : boolean; virtual;
  1370. procedure StartTransaction; override;
  1371. procedure EndTransaction; override;
  1372. published
  1373. property AfterConnect : TNotifyEvent read FAfterConnect write SetAfterConnect;
  1374. property BeforeConnect : TNotifyEvent read FBeforeConnect write SetBeforeConnect;
  1375. property AfterDisconnect : TNotifyEvent read FAfterDisconnect write SetAfterDisconnect;
  1376. property BeforeDisconnect : TNotifyEvent read FBeforeDisconnect write SetBeforeDisconnect;
  1377. end;
  1378. { TParam }
  1379. TBlobData = string;
  1380. TParamBinding = array of integer;
  1381. TParamType = (ptUnknown, ptInput, ptOutput, ptInputOutput, ptResult);
  1382. TParamTypes = set of TParamType;
  1383. TParamStyle = (psInterbase,psPostgreSQL,psSimulated);
  1384. TParams = class;
  1385. TParam = class(TCollectionItem)
  1386. private
  1387. FNativeStr: string;
  1388. FValue: Variant;
  1389. FPrecision: Integer;
  1390. FNumericScale: Integer;
  1391. FName: string;
  1392. FDataType: TFieldType;
  1393. FBound: Boolean;
  1394. FParamType: TParamType;
  1395. FSize: Integer;
  1396. Function GetDataSet: TDataSet;
  1397. Function IsParamStored: Boolean;
  1398. protected
  1399. Procedure AssignParam(Param: TParam);
  1400. Procedure AssignTo(Dest: TPersistent); override;
  1401. Function GetAsBoolean: Boolean;
  1402. Function GetAsCurrency: Currency;
  1403. Function GetAsDateTime: TDateTime;
  1404. Function GetAsFloat: Double;
  1405. Function GetAsInteger: Longint;
  1406. Function GetAsLargeInt: LargeInt;
  1407. Function GetAsMemo: string;
  1408. Function GetAsString: string;
  1409. Function GetAsVariant: Variant;
  1410. Function GetDisplayName: string; override;
  1411. Function GetIsNull: Boolean;
  1412. Function IsEqual(AValue: TParam): Boolean;
  1413. Procedure SetAsBlob(const AValue: TBlobData);
  1414. Procedure SetAsBoolean(AValue: Boolean);
  1415. Procedure SetAsCurrency(const AValue: Currency);
  1416. Procedure SetAsDate(const AValue: TDateTime);
  1417. Procedure SetAsDateTime(const AValue: TDateTime);
  1418. Procedure SetAsFloat(const AValue: Double);
  1419. Procedure SetAsInteger(AValue: Longint);
  1420. Procedure SetAsLargeInt(AValue: LargeInt);
  1421. Procedure SetAsMemo(const AValue: string);
  1422. Procedure SetAsSmallInt(AValue: LongInt);
  1423. Procedure SetAsString(const AValue: string);
  1424. Procedure SetAsTime(const AValue: TDateTime);
  1425. Procedure SetAsVariant(const AValue: Variant);
  1426. Procedure SetAsWord(AValue: LongInt);
  1427. Procedure SetDataType(AValue: TFieldType);
  1428. Procedure SetText(const AValue: string);
  1429. public
  1430. constructor Create(ACollection: TCollection); overload; override;
  1431. constructor Create(AParams: TParams; AParamType: TParamType); reintroduce; overload;
  1432. Procedure Assign(Source: TPersistent); override;
  1433. Procedure AssignField(Field: TField);
  1434. Procedure AssignToField(Field: TField);
  1435. Procedure AssignFieldValue(Field: TField; const AValue: Variant);
  1436. procedure AssignFromField(Field : TField);
  1437. Procedure Clear;
  1438. Procedure GetData(Buffer: Pointer);
  1439. Function GetDataSize: Integer;
  1440. Procedure LoadFromFile(const FileName: string; BlobType: TBlobType);
  1441. Procedure LoadFromStream(Stream: TStream; BlobType: TBlobType);
  1442. Procedure SetBlobData(Buffer: Pointer; ASize: Integer);
  1443. Procedure SetData(Buffer: Pointer);
  1444. Property AsBlob : TBlobData read GetAsString write SetAsBlob;
  1445. Property AsBoolean : Boolean read GetAsBoolean write SetAsBoolean;
  1446. Property AsCurrency : Currency read GetAsCurrency write SetAsCurrency;
  1447. Property AsDate : TDateTime read GetAsDateTime write SetAsDate;
  1448. Property AsDateTime : TDateTime read GetAsDateTime write SetAsDateTime;
  1449. Property AsFloat : Double read GetAsFloat write SetAsFloat;
  1450. Property AsInteger : LongInt read GetAsInteger write SetAsInteger;
  1451. Property AsLargeInt : LargeInt read GetAsLargeInt write SetAsLargeInt;
  1452. Property AsMemo : string read GetAsMemo write SetAsMemo;
  1453. Property AsSmallInt : LongInt read GetAsInteger write SetAsSmallInt;
  1454. Property AsString : string read GetAsString write SetAsString;
  1455. Property AsTime : TDateTime read GetAsDateTime write SetAsTime;
  1456. Property AsWord : LongInt read GetAsInteger write SetAsWord;
  1457. Property Bound : Boolean read FBound write FBound;
  1458. Property Dataset : TDataset Read GetDataset;
  1459. Property IsNull : Boolean read GetIsNull;
  1460. Property NativeStr : string read FNativeStr write FNativeStr;
  1461. Property Text : string read GetAsString write SetText;
  1462. Property Value : Variant read GetAsVariant write SetAsVariant stored IsParamStored;
  1463. published
  1464. Property DataType : TFieldType read FDataType write SetDataType;
  1465. Property Name : string read FName write FName;
  1466. Property NumericScale : Integer read FNumericScale write FNumericScale default 0;
  1467. Property ParamType : TParamType read FParamType write FParamType;
  1468. Property Precision : Integer read FPrecision write FPrecision default 0;
  1469. Property Size : Integer read FSize write FSize default 0;
  1470. end;
  1471. { TParams }
  1472. TParams = class(TCollection)
  1473. private
  1474. FOwner: TPersistent;
  1475. Function GetItem(Index: Integer): TParam;
  1476. Function GetParamValue(const ParamName: string): Variant;
  1477. Procedure SetItem(Index: Integer; Value: TParam);
  1478. Procedure SetParamValue(const ParamName: string; const Value: Variant);
  1479. protected
  1480. Procedure AssignTo(Dest: TPersistent); override;
  1481. Function GetDataSet: TDataSet;
  1482. Function GetOwner: TPersistent; override;
  1483. public
  1484. Constructor Create(AOwner: TPersistent); overload;
  1485. Constructor Create; overload;
  1486. Procedure AddParam(Value: TParam);
  1487. Procedure AssignValues(Value: TParams);
  1488. Function CreateParam(FldType: TFieldType; const ParamName: string; ParamType: TParamType): TParam;
  1489. Function FindParam(const Value: string): TParam;
  1490. Procedure GetParamList(List: TList; const ParamNames: string);
  1491. Function IsEqual(Value: TParams): Boolean;
  1492. Function ParamByName(const Value: string): TParam;
  1493. Function ParseSQL(SQL: String; DoCreate: Boolean): String;
  1494. Function ParseSQL(SQL: String; DoCreate, EscapeSlash, EscapeRepeat : Boolean; ParameterStyle : TParamStyle): String; overload;
  1495. Function ParseSQL(SQL: String; DoCreate, EscapeSlash, EscapeRepeat : Boolean; ParameterStyle : TParamStyle; var ParamBinding: TParambinding): String; overload;
  1496. Function ParseSQL(SQL: String; DoCreate, EscapeSlash, EscapeRepeat : Boolean; ParameterStyle : TParamStyle; var ParamBinding: TParambinding; var ReplaceString : string): String;
  1497. Procedure RemoveParam(Value: TParam);
  1498. Procedure CopyParamValuesFromDataset(ADataset : TDataset; CopyBound : Boolean);
  1499. Property Dataset : TDataset Read GetDataset;
  1500. Property Items[Index: Integer] : TParam read GetItem write SetItem; default;
  1501. Property ParamValues[const ParamName: string] : Variant read GetParamValue write SetParamValue;
  1502. end;
  1503. TMasterParamsDataLink = Class(TMasterDataLink)
  1504. Private
  1505. FParams : TParams;
  1506. Procedure SetParams(AVAlue : TParams);
  1507. Protected
  1508. Procedure DoMasterDisable; override;
  1509. Procedure DoMasterChange; override;
  1510. Public
  1511. constructor Create(ADataSet: TDataSet); override;
  1512. Procedure RefreshParamNames; virtual;
  1513. Procedure CopyParamsFromMaster(CopyBound : Boolean); virtual;
  1514. Property Params : TParams Read FParams Write SetParams;
  1515. end;
  1516. const
  1517. FieldTypetoVariantMap : array[TFieldType] of Integer = (varError, varOleStr, varSmallint,
  1518. varInteger, varSmallint, varBoolean, varDouble, varCurrency, varCurrency,
  1519. varDate, varDate, varDate, varOleStr, varOleStr, varInteger, varOleStr,
  1520. varOleStr, varOleStr, varOleStr, varOleStr, varOleStr, varOleStr, varError,
  1521. varOleStr, varOleStr, varError, varError, varError, varError, varError,
  1522. varOleStr, varOleStr, varVariant, varUnknown, varDispatch, varOleStr, varOleStr,varOleStr);
  1523. Const
  1524. Fieldtypenames : Array [TFieldType] of String[15] =
  1525. (
  1526. 'Unknown',
  1527. 'String',
  1528. 'Smallint',
  1529. 'Integer',
  1530. 'Word',
  1531. 'Boolean',
  1532. 'Float',
  1533. 'Currency',
  1534. 'BCD',
  1535. 'Date',
  1536. 'Time',
  1537. 'DateTime',
  1538. 'Bytes',
  1539. 'VarBytes',
  1540. 'AutoInc',
  1541. 'Blob',
  1542. 'Memo',
  1543. 'Graphic',
  1544. 'FmtMemo',
  1545. 'ParadoxOle',
  1546. 'DBaseOle',
  1547. 'TypedBinary',
  1548. 'Cursor',
  1549. 'FixedChar',
  1550. 'WideString',
  1551. 'Largeint',
  1552. 'ADT',
  1553. 'Array',
  1554. 'Reference',
  1555. 'DataSet',
  1556. 'OraBlob',
  1557. 'OraClob',
  1558. 'Variant',
  1559. 'Interface',
  1560. 'IDispatch',
  1561. 'Guid',
  1562. 'TimeStamp',
  1563. 'FMTBcd'
  1564. );
  1565. { 'Unknown',
  1566. 'String',
  1567. 'Smallint',
  1568. 'Integer',
  1569. 'Word',
  1570. 'Boolean',
  1571. 'Float',
  1572. 'Date',
  1573. 'Time',
  1574. 'DateTime',
  1575. 'Bytes',
  1576. 'VarBytes',
  1577. 'AutoInc',
  1578. 'Blob',
  1579. 'Memo',
  1580. 'Graphic',
  1581. 'FmtMemo',
  1582. 'ParadoxOle',
  1583. 'DBaseOle',
  1584. 'TypedBinary',
  1585. 'Cursor'
  1586. );}
  1587. const
  1588. DefaultFieldClasses : Array [TFieldType] of TFieldClass =
  1589. ( { ftUnknown} Tfield,
  1590. { ftString} TStringField,
  1591. { ftSmallint} TSmallIntField,
  1592. { ftInteger} TLongintField,
  1593. { ftWord} TLongintField,
  1594. { ftBoolean} TBooleanField,
  1595. { ftFloat} TFloatField,
  1596. { ftCurrency} Nil,
  1597. { ftBCD} TBCDField,
  1598. { ftDate} TDateField,
  1599. { ftTime} TTimeField,
  1600. { ftDateTime} TDateTimeField,
  1601. { ftBytes} TBytesField,
  1602. { ftVarBytes} TVarBytesField,
  1603. { ftAutoInc} TAutoIncField,
  1604. { ftBlob} TBlobField,
  1605. { ftMemo} TMemoField,
  1606. { ftGraphic} TGraphicField,
  1607. { ftFmtMemo} TMemoField,
  1608. { ftParadoxOle} Nil,
  1609. { ftDBaseOle} Nil,
  1610. { ftTypedBinary} Nil,
  1611. { ftCursor} Nil,
  1612. { ftFixedChar} TStringField,
  1613. { ftWideString} Nil,
  1614. { ftLargeint} TLargeIntField,
  1615. { ftADT} Nil,
  1616. { ftArray} Nil,
  1617. { ftReference} Nil,
  1618. { ftDataSet} Nil,
  1619. { ftOraBlob} TBlobField,
  1620. { ftOraClob} TMemoField,
  1621. { ftVariant} Nil,
  1622. { ftInterface} Nil,
  1623. { ftIDispatch} Nil,
  1624. { ftGuid} Nil,
  1625. { ftTimeStamp} Nil,
  1626. { ftFMTBcd} Nil
  1627. );
  1628. dsEditModes = [dsEdit, dsInsert, dsSetKey];
  1629. dsWriteModes = [dsEdit, dsInsert, dsSetKey, dsCalcFields, dsFilter,
  1630. dsNewValue, dsInternalCalc];
  1631. { Auxiliary functions }
  1632. Procedure DatabaseError (Const Msg : String);
  1633. Procedure DatabaseError (Const Msg : String; Comp : TComponent);
  1634. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of Const);
  1635. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of const;
  1636. Comp : TComponent);
  1637. Function ExtractFieldName(Const Fields: String; var Pos: Integer): String;
  1638. Function DateTimeRecToDateTime(DT: TFieldType; Data: TDateTimeRec): TDateTime;
  1639. Function DateTimeToDateTimeRec(DT: TFieldType; Data: TDateTime): TDateTimeRec;
  1640. procedure DisposeMem(var Buffer; Size: Integer);
  1641. function BuffersEqual(Buf1, Buf2: Pointer; Size: Integer): Boolean;
  1642. function SkipComments(var p: PChar; EscapeSlash, EscapeRepeat : Boolean) : boolean;
  1643. implementation
  1644. uses dbconst,typinfo, fmtbcd;
  1645. { ---------------------------------------------------------------------
  1646. Auxiliary functions
  1647. ---------------------------------------------------------------------}
  1648. Procedure DatabaseError (Const Msg : String);
  1649. begin
  1650. Raise EDataBaseError.Create(Msg);
  1651. end;
  1652. Procedure DatabaseError (Const Msg : String; Comp : TComponent);
  1653. begin
  1654. if assigned(Comp) and (Comp.Name <> '') then
  1655. Raise EDatabaseError.CreateFmt('%s : %s',[Comp.Name,Msg])
  1656. else
  1657. DatabaseError(Msg);
  1658. end;
  1659. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of Const);
  1660. begin
  1661. Raise EDatabaseError.CreateFmt(Fmt,Args);
  1662. end;
  1663. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of const;
  1664. Comp : TComponent);
  1665. begin
  1666. if assigned(comp) then
  1667. Raise EDatabaseError.CreateFmt(Format('%s : %s',[Comp.Name,Fmt]),Args)
  1668. else
  1669. DatabaseErrorFmt(Fmt, Args);
  1670. end;
  1671. Function ExtractFieldName(Const Fields: String; var Pos: Integer): String;
  1672. var
  1673. i: integer;
  1674. begin
  1675. for i := Pos to Length(Fields) do begin
  1676. if Fields[i] = ';' then begin
  1677. Result := Copy(Fields, Pos, i - Pos);
  1678. Pos := i + 1;
  1679. Exit;
  1680. end;
  1681. end;
  1682. Result := Copy(Fields, Pos, Length(Fields));
  1683. Pos := Length(Fields) + 1;
  1684. end;
  1685. { EUpdateError }
  1686. constructor EUpdateError.Create(NativeError, Context : String;
  1687. ErrCode, PrevError : integer; E: Exception);
  1688. begin
  1689. Inherited CreateFmt(NativeError,[Context]);
  1690. FContext := Context;
  1691. FErrorCode := ErrCode;
  1692. FPreviousError := PrevError;
  1693. FOriginalException := E;
  1694. end;
  1695. Destructor EUpdateError.Destroy;
  1696. begin
  1697. FOriginalException.Free;
  1698. Inherited;
  1699. end;
  1700. { TIndexDef }
  1701. procedure TIndexDef.SetDescFields(const AValue: string);
  1702. begin
  1703. if FDescFields=AValue then exit;
  1704. if AValue <> '' then FOptions:=FOptions + [ixDescending];
  1705. FDescFields:=AValue;
  1706. end;
  1707. procedure TIndexDef.SetCaseInsFields(const AValue: string);
  1708. begin
  1709. if FCaseinsFields=AValue then exit;
  1710. if AValue <> '' then FOptions:=FOptions + [ixCaseInsensitive];
  1711. FCaseinsFields:=AValue;
  1712. end;
  1713. constructor TIndexDef.Create(Owner: TIndexDefs; const AName, TheFields: string;
  1714. TheOptions: TIndexOptions);
  1715. begin
  1716. inherited create(Owner);
  1717. FName := aname;
  1718. FFields := TheFields;
  1719. FOptions := TheOptions;
  1720. end;
  1721. destructor TIndexDef.Destroy;
  1722. begin
  1723. inherited Destroy;
  1724. end;
  1725. { TIndexDefs }
  1726. Function TIndexDefs.GetItem (Index : integer) : TIndexDef;
  1727. begin
  1728. Result:=(Inherited GetItem(Index)) as TIndexDef;
  1729. end;
  1730. Procedure TIndexDefs.SetItem(Index: Integer; Value: TIndexDef);
  1731. begin
  1732. Inherited SetItem(Index,Value);
  1733. end;
  1734. constructor TIndexDefs.Create(DataSet: TDataSet);
  1735. begin
  1736. FDataset := Dataset;
  1737. inherited create(Dataset, TIndexDef);
  1738. end;
  1739. destructor TIndexDefs.Destroy;
  1740. begin
  1741. inherited Destroy;
  1742. end;
  1743. Function TIndexDefs.AddIndexDef: TIndexDef;
  1744. begin
  1745. // Result := inherited add as TIndexDef;
  1746. Result:=TIndexDef.Create(Self,'','',[]);
  1747. end;
  1748. procedure TIndexDefs.Add(const Name, Fields: string; Options: TIndexOptions);
  1749. begin
  1750. TIndexDef.Create(Self,Name,Fields,Options);
  1751. end;
  1752. procedure TIndexDefs.Assign(IndexDefs: TIndexDefs);
  1753. begin
  1754. //!! To be implemented
  1755. end;
  1756. {procedure TIndexDefs.Clear;
  1757. begin
  1758. //!! To be implemented
  1759. end;}
  1760. function TIndexDefs.Find(const IndexName: string): TIndexDef;
  1761. var i: integer;
  1762. begin
  1763. Result := Nil;
  1764. for i := 0 to Count - 1 do
  1765. if AnsiSameText(Items[i].Name, IndexName) then begin
  1766. Result := Items[i];
  1767. Break;
  1768. end;
  1769. if (Result=Nil) Then
  1770. DatabaseErrorFmt(SIndexNotFound, [IndexName], FDataSet);
  1771. end;
  1772. function TIndexDefs.FindIndexForFields(const Fields: string): TIndexDef;
  1773. begin
  1774. //!! To be implemented
  1775. end;
  1776. function TIndexDefs.GetIndexForFields(const Fields: string;
  1777. CaseInsensitive: Boolean): TIndexDef;
  1778. var
  1779. i, FieldsLen: integer;
  1780. Last: TIndexDef;
  1781. begin
  1782. Last := nil;
  1783. FieldsLen := Length(Fields);
  1784. for i := 0 to Count - 1 do
  1785. begin
  1786. Result := Items[I];
  1787. if (Result.Options * [ixDescending, ixExpression] = []) and
  1788. (not CaseInsensitive or (ixCaseInsensitive in Result.Options)) and
  1789. AnsiSameText(Fields, Result.Fields) then
  1790. begin
  1791. Exit;
  1792. end else
  1793. if AnsiSameText(Fields, Copy(Result.Fields, 1, FieldsLen)) and
  1794. ((Length(Result.Fields) = FieldsLen) or
  1795. (Result.Fields[FieldsLen + 1] = ';')) then
  1796. begin
  1797. if (Last = nil) or
  1798. ((Last <> nil) And (Length(Last.Fields) > Length(Result.Fields))) then
  1799. Last := Result;
  1800. end;
  1801. end;
  1802. Result := Last;
  1803. end;
  1804. function TIndexDefs.IndexOf(const Name: string): Longint;
  1805. var i: LongInt;
  1806. begin
  1807. Result := -1;
  1808. for i := 0 to Count - 1 do
  1809. if AnsiSameText(Items[i].Name, Name) then
  1810. begin
  1811. Result := i;
  1812. Break;
  1813. end;
  1814. end;
  1815. procedure TIndexDefs.Update;
  1816. begin
  1817. if assigned(Fdataset) then
  1818. Fdataset.UpdateIndexDefs;
  1819. end;
  1820. { TCheckConstraint }
  1821. procedure TCheckConstraint.Assign(Source: TPersistent);
  1822. begin
  1823. //!! To be implemented
  1824. end;
  1825. { TCheckConstraints }
  1826. Function TCheckConstraints.GetItem(Index : Longint) : TCheckConstraint;
  1827. begin
  1828. //!! To be implemented
  1829. end;
  1830. Procedure TCheckConstraints.SetItem(index : Longint; Value : TCheckConstraint);
  1831. begin
  1832. //!! To be implemented
  1833. end;
  1834. function TCheckConstraints.GetOwner: TPersistent;
  1835. begin
  1836. //!! To be implemented
  1837. end;
  1838. constructor TCheckConstraints.Create(AOwner: TPersistent);
  1839. begin
  1840. //!! To be implemented
  1841. end;
  1842. function TCheckConstraints.Add: TCheckConstraint;
  1843. begin
  1844. //!! To be implemented
  1845. end;
  1846. { TLookupList }
  1847. constructor TLookupList.Create;
  1848. begin
  1849. FList := TList.Create;
  1850. end;
  1851. destructor TLookupList.Destroy;
  1852. begin
  1853. if FList <> nil then Clear;
  1854. FList.Free;
  1855. inherited Destroy;
  1856. end;
  1857. procedure TLookupList.Add(const AKey, AValue: Variant);
  1858. var LookupRec: PLookupListRec;
  1859. begin
  1860. New(LookupRec);
  1861. LookupRec^.Key := AKey;
  1862. LookupRec^.Value := AValue;
  1863. FList.Add(LookupRec);
  1864. end;
  1865. procedure TLookupList.Clear;
  1866. var i: integer;
  1867. begin
  1868. for i := 0 to FList.Count - 1 do Dispose(PLookupListRec(FList[i]));
  1869. FList.Clear;
  1870. end;
  1871. function TLookupList.ValueOfKey(const AKey: Variant): Variant;
  1872. var I: Integer;
  1873. begin
  1874. Result := Null;
  1875. if VarIsNull(AKey) then Exit;
  1876. i := FList.Count - 1;
  1877. while (i > 0) And (PLookupListRec(FList.Items[I])^.Key <> AKey) do Dec(i);
  1878. if i >= 0 then Result := PLookupListRec(FList.Items[I])^.Value;
  1879. end;
  1880. procedure DisposeMem(var Buffer; Size: Integer);
  1881. begin
  1882. if Pointer(Buffer) <> nil then
  1883. begin
  1884. FreeMem(Pointer(Buffer), Size);
  1885. Pointer(Buffer) := nil;
  1886. end;
  1887. end;
  1888. function BuffersEqual(Buf1, Buf2: Pointer; Size: Integer): Boolean;
  1889. begin
  1890. Result:=CompareByte(Buf1,Buf2,Size)=0
  1891. end;
  1892. {$i dataset.inc}
  1893. {$i fields.inc}
  1894. {$i datasource.inc}
  1895. {$i database.inc}
  1896. {$i dsparams.inc}
  1897. end.