db.pp 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt, member of the
  5. Free Pascal development team
  6. DB header file with interface section.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit db;
  14. {$mode objfpc}
  15. {$h+}
  16. interface
  17. uses Classes,Sysutils;
  18. const
  19. dsMaxBufferCount = MAXINT div 8;
  20. dsMaxStringSize = 8192;
  21. // Used in AsBoolean for string fields to determine
  22. // whether it's true or false.
  23. YesNoChars : Array[Boolean] of char = ('Y','N');
  24. type
  25. {LargeInt}
  26. LargeInt = Int64;
  27. { Auxiliary type }
  28. TStringFieldBuffer = Array[0..dsMaxStringSize] of Char;
  29. { Misc Dataset types }
  30. TDataSetState = (dsInactive, dsBrowse, dsEdit, dsInsert, dsSetKey,
  31. dsCalcFields, dsFilter, dsNewValue, dsOldValue, dsCurValue);
  32. TDataEvent = (deFieldChange, deRecordChange, deDataSetChange,
  33. deDataSetScroll, deLayoutChange, deUpdateRecord, deUpdateState,
  34. deCheckBrowseMode, dePropertyChange, deFieldListChange, deFocusControl);
  35. TUpdateStatus = (usUnmodified, usModified, usInserted, usDeleted);
  36. { Forward declarations }
  37. TFieldDef = class;
  38. TFieldDefs = class;
  39. TField = class;
  40. TFields = Class;
  41. TDataSet = class;
  42. TDataBase = Class;
  43. TDatasource = Class;
  44. TDatalink = Class;
  45. { Exception classes }
  46. EDatabaseError = class(Exception);
  47. { TFieldDef }
  48. TFieldClass = class of TField;
  49. {
  50. TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
  51. ftBoolean, ftFloat, ftDate, ftTime, ftDateTime,
  52. ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic,
  53. ftFmtMemo, ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor);
  54. }
  55. TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
  56. ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime,
  57. ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo,
  58. ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar,
  59. ftWideString, ftLargeint, ftADT, ftArray, ftReference,
  60. ftDataSet, ftOraBlob, ftOraClob, ftVariant, ftInterface,
  61. ftIDispatch, ftGuid, ftTimeStamp, ftFMTBcd);
  62. TFieldDef = class(TComponent)
  63. Private
  64. FDataType : TFieldType;
  65. FFieldNo : Longint;
  66. FInternalCalcField : Boolean;
  67. FPrecision : Longint;
  68. FRequired : Boolean;
  69. FSize : Word;
  70. FName : String;
  71. Function GetFieldClass : TFieldClass;
  72. public
  73. constructor Create(AOwner: TFieldDefs; const AName: string;
  74. ADataType: TFieldType; ASize: Word; ARequired: Boolean; AFieldNo: Longint);
  75. destructor Destroy; override;
  76. function CreateField(AOwner: TComponent): TField;
  77. property InternalCalcField: Boolean read FInternalCalcField write FInternalCalcField;
  78. property DataType: TFieldType read FDataType;
  79. property FieldClass: TFieldClass read GetFieldClass;
  80. property FieldNo: Longint read FFieldNo;
  81. property Name: string read FName;
  82. property Precision: Longint read FPrecision write FPrecision;
  83. property Required: Boolean read FRequired;
  84. property Size: Word read FSize;
  85. end;
  86. { TFieldDefs }
  87. TFieldDefs = class(TComponent)
  88. private
  89. FDataSet: TDataSet;
  90. FItems: TList;
  91. FUpdated: Boolean;
  92. function GetCount: Longint;
  93. function GetItem(Index: Longint): TFieldDef;
  94. public
  95. constructor Create(ADataSet: TDataSet);
  96. destructor Destroy; override;
  97. procedure Add(const AName: string; ADataType: TFieldType; ASize: Word;
  98. ARequired: Boolean);
  99. procedure Assign(FieldDefs: TFieldDefs);
  100. procedure Clear;
  101. function Find(const AName: string): TFieldDef;
  102. function IndexOf(const AName: string): Longint;
  103. procedure Update;
  104. property Count: Longint read GetCount;
  105. property Items[Index: Longint]: TFieldDef read GetItem; default;
  106. end;
  107. { TField }
  108. TFieldKind = (fkData, fkCalculated, fkLookup, fkInternalCalc);
  109. TFieldKinds = Set of TFieldKind;
  110. TFieldNotifyEvent = procedure(Sender: TField) of object;
  111. TFieldGetTextEvent = procedure(Sender: TField; var Text: string;
  112. DisplayText: Boolean) of object;
  113. TFieldSetTextEvent = procedure(Sender: TField; const Text: string) of object;
  114. TFieldRef = ^TField;
  115. TFieldChars = set of Char;
  116. { TAlignment may need to come from somewhere else }
  117. TAlignMent = (taLeftjustify,taCenter,taRightJustify);
  118. TField = class(TComponent)
  119. Private
  120. FAlignMent : TAlignment;
  121. FAttributeSet : String;
  122. FBuffers : ppchar;
  123. FCalculated : Boolean;
  124. FCanModify : Boolean;
  125. FConstraintErrorMessage : String;
  126. FCustomConstraint : String;
  127. FDataSet : TDataSet;
  128. FDataSize : Word;
  129. FDataType : TFieldType;
  130. FDefaultExpression : String;
  131. FDisplayLabel : String;
  132. FDisplayWidth : Longint;
  133. FEditText : String;
  134. FFieldKind : TFieldKind;
  135. FFieldName : String;
  136. FFieldNo : Longint;
  137. FFields : TFields;
  138. FHasConstraints : Boolean;
  139. FImportedConstraint : String;
  140. FIsIndexField : Boolean;
  141. FKeyFields : String;
  142. FLookupCache : Boolean;
  143. FLookupDataSet : TDataSet;
  144. FLookupKeyfields : String;
  145. FLookupresultField : String;
  146. FOffset : Word;
  147. FOnChange : TFieldNotifyEvent;
  148. FOnGetText: TFieldGetTextEvent;
  149. FOnSetText: TFieldSetTextEvent;
  150. FOnValidate: TFieldNotifyEvent;
  151. FOrigin : String;
  152. FReadOnly : Boolean;
  153. FRequired : Boolean;
  154. FSize : Word;
  155. FValidChars : TFieldChars;
  156. FValueBuffer : Pointer;
  157. FValidating : Boolean;
  158. FVisible : Boolean;
  159. Function GetIndex : longint;
  160. Procedure SetDataset(VAlue : TDataset);
  161. function GetDisplayText: String;
  162. protected
  163. function AccessError(const TypeName: string): EDatabaseError;
  164. procedure CheckInactive;
  165. class procedure CheckTypeSize(AValue: Longint); virtual;
  166. procedure Change; virtual;
  167. procedure DataChanged;
  168. procedure FreeBuffers; virtual;
  169. function GetAsBoolean: Boolean; virtual;
  170. function GetAsDateTime: TDateTime; virtual;
  171. function GetAsFloat: Extended; virtual;
  172. function GetAsLongint: Longint; virtual;
  173. function GetAsString: string; virtual;
  174. function GetCanModify: Boolean; virtual;
  175. function GetDataSize: Word; virtual;
  176. function GetDefaultWidth: Longint; virtual;
  177. function GetDisplayName : String;
  178. function GetIsNull: Boolean; virtual;
  179. function GetParentComponent: TComponent; override;
  180. procedure GetText(var AText: string; ADisplayText: Boolean); virtual;
  181. function HasParent: Boolean; override;
  182. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  183. procedure PropertyChanged(LayoutAffected: Boolean);
  184. procedure ReadState(Reader: TReader); override;
  185. procedure SetAsBoolean(AValue: Boolean); virtual;
  186. procedure SetAsDateTime(AValue: TDateTime); virtual;
  187. procedure SetAsFloat(AValue: Extended); virtual;
  188. procedure SetAsLongint(AValue: Longint); virtual;
  189. procedure SetAsString(const AValue: string); virtual;
  190. procedure SetDataType(AValue: TFieldType);
  191. procedure SetSize(AValue: Word); virtual;
  192. procedure SetParentComponent(AParent: TComponent); override;
  193. procedure SetText(const AValue: string); virtual;
  194. public
  195. constructor Create(AOwner: TComponent); override;
  196. destructor Destroy; override;
  197. procedure Assign(Source: TPersistent); override;
  198. procedure Clear; virtual;
  199. procedure FocusControl;
  200. function GetData(Buffer: Pointer): Boolean;
  201. class function IsBlob: Boolean; virtual;
  202. function IsValidChar(InputChar: Char): Boolean; virtual;
  203. procedure SetData(Buffer: Pointer);
  204. procedure SetFieldType(AValue: TFieldType); virtual;
  205. procedure Validate(Buffer: Pointer);
  206. property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;
  207. property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
  208. property AsFloat: Extended read GetAsFloat write SetAsFloat;
  209. property AsLongint: Longint read GetAsLongint write SetAsLongint;
  210. property AsString: string read GetAsString write SetAsString;
  211. property AttributeSet: string read FAttributeSet write FAttributeSet;
  212. property Calculated: Boolean read FCalculated write FCalculated;
  213. property CanModify: Boolean read FCanModify;
  214. property DataSet: TDataSet read FDataSet write SetDataSet;
  215. property DataSize: Word read GetDataSize;
  216. property DataType: TFieldType read FDataType;
  217. property DisplayName: String Read GetDisplayName;
  218. property DisplayText: String read GetDisplayText;
  219. property FieldNo: Longint read FFieldNo;
  220. property IsIndexField: Boolean read FIsIndexField;
  221. property IsNull: Boolean read GetIsNull;
  222. property Offset: word read FOffset;
  223. property Size: Word read FSize write FSize;
  224. property Text: string read FEditText write FEditText;
  225. property ValidChars : TFieldChars Read FValidChars;
  226. published
  227. property AlignMent : TAlignMent Read FAlignMent write FAlignment;
  228. property CustomConstraint: string read FCustomConstraint write FCustomConstraint;
  229. property ConstraintErrorMessage: string read FConstraintErrorMessage write FConstraintErrorMessage;
  230. property DefaultExpression: string read FDefaultExpression write FDefaultExpression;
  231. property DisplayLabel : string read FDisplayLabel write FDisplayLabel;
  232. property DisplayWidth: Longint read FDisplayWidth write FDisplayWidth;
  233. property FieldKind: TFieldKind read FFieldKind write FFieldKind;
  234. property FieldName: string read FFieldName write FFieldName;
  235. property HasConstraints: Boolean read FHasConstraints;
  236. property Index: Longint read GetIndex;
  237. property ImportedConstraint: string read FImportedConstraint write FImportedConstraint;
  238. property LookupDataSet: TDataSet read FLookupDataSet write FLookupDataSet;
  239. property LookupKeyFields: string read FLookupKeyFields write FLookupKeyFields;
  240. property LookupResultField: string read FLookupResultField write FLookupResultField;
  241. property KeyFields: string read FKeyFields write FKeyFields;
  242. property LookupCache: Boolean read FLookupCache write FLookupCache;
  243. property Origin: string read FOrigin write FOrigin;
  244. property ReadOnly: Boolean read FReadOnly write FReadOnly;
  245. property Required: Boolean read FRequired write FRequired;
  246. property Visible: Boolean read FVisible write FVisible;
  247. property OnChange: TFieldNotifyEvent read FOnChange write FOnChange;
  248. property OnGetText: TFieldGetTextEvent read FOnGetText write FOnGetText;
  249. property OnSetText: TFieldSetTextEvent read FOnSetText write FOnSetText;
  250. property OnValidate: TFieldNotifyEvent read FOnValidate write FOnValidate;
  251. end;
  252. { TStringField }
  253. TStringField = class(TField)
  254. protected
  255. class procedure CheckTypeSize(AValue: Longint); override;
  256. function GetAsBoolean: Boolean; override;
  257. function GetAsDateTime: TDateTime; override;
  258. function GetAsFloat: Extended; override;
  259. function GetAsLongint: Longint; override;
  260. function GetAsString: string; override;
  261. function GetDataSize: Word; override;
  262. function GetDefaultWidth: Longint; override;
  263. procedure GetText(var AText: string; ADisplayText: Boolean); override;
  264. function GetValue(var AValue: string): Boolean;
  265. procedure SetAsBoolean(AValue: Boolean); override;
  266. procedure SetAsDateTime(AValue: TDateTime); override;
  267. procedure SetAsFloat(AValue: Extended); override;
  268. procedure SetAsLongint(AValue: Longint); override;
  269. procedure SetAsString(const AValue: string); override;
  270. public
  271. constructor Create(AOwner: TComponent); override;
  272. property Value: string read GetAsString write SetAsString;
  273. published
  274. property Size default 20;
  275. end;
  276. { TNumericField }
  277. TNumericField = class(TField)
  278. Private
  279. FDisplayFormat : String;
  280. FEditFormat : String;
  281. protected
  282. procedure RangeError(AValue, Min, Max: Extended);
  283. procedure SetDisplayFormat(const AValue: string);
  284. procedure SetEditFormat(const AValue: string);
  285. public
  286. constructor Create(AOwner: TComponent); override;
  287. published
  288. property DisplayFormat: string read FDisplayFormat write SetDisplayFormat;
  289. property EditFormat: string read FEditFormat write SetEditFormat;
  290. end;
  291. { TLongintField }
  292. TLongintField = class(TNumericField)
  293. private
  294. FMinValue,
  295. FMaxValue,
  296. FMinRange,
  297. FMAxRange : Longint;
  298. Procedure SetMinValue (AValue : longint);
  299. Procedure SetMaxValue (AValue : longint);
  300. protected
  301. function GetAsFloat: Extended; override;
  302. function GetAsLongint: Longint; override;
  303. function GetAsString: string; override;
  304. function GetDataSize: Word; override;
  305. procedure GetText(var AText: string; ADisplayText: Boolean); override;
  306. function GetValue(var AValue: Longint): Boolean;
  307. procedure SetAsFloat(AValue: Extended); override;
  308. procedure SetAsLongint(AValue: Longint); override;
  309. procedure SetAsString(const AValue: string); override;
  310. public
  311. constructor Create(AOwner: TComponent); override;
  312. Function CheckRange(AValue : longint) : Boolean;
  313. property Value: Longint read GetAsLongint write SetAsLongint;
  314. published
  315. property MaxValue: Longint read FMaxValue write SetMaxValue default 0;
  316. property MinValue: Longint read FMinValue write SetMinValue default 0;
  317. end;
  318. TIntegerField = TLongintField;
  319. { TSmallintField }
  320. TSmallintField = class(TLongintField)
  321. protected
  322. function GetDataSize: Word; override;
  323. public
  324. constructor Create(AOwner: TComponent); override;
  325. end;
  326. { TWordField }
  327. TWordField = class(TLongintField)
  328. protected
  329. function GetDataSize: Word; override;
  330. public
  331. constructor Create(AOwner: TComponent); override;
  332. end;
  333. { TAutoIncField }
  334. TAutoIncField = class(TLongintField)
  335. Protected
  336. Procedure SetAsLongInt(AValue : Longint); override;
  337. public
  338. constructor Create(AOwner: TComponent); override;
  339. end;
  340. { TFloatField }
  341. TFloatField = class(TNumericField)
  342. private
  343. FMaxValue : Extended;
  344. FMinValue : Extended;
  345. FPrecision : Longint;
  346. protected
  347. function GetAsFloat: Extended; override;
  348. function GetAsLongint: Longint; override;
  349. function GetAsString: string; override;
  350. function GetDataSize: Word; override;
  351. procedure GetText(var theText: string; ADisplayText: Boolean); override;
  352. procedure SetAsFloat(AValue: Extended); override;
  353. procedure SetAsLongint(AValue: Longint); override;
  354. procedure SetAsString(const AValue: string); override;
  355. public
  356. constructor Create(AOwner: TComponent); override;
  357. Function CheckRange(AValue : Extended) : Boolean;
  358. property Value: Extended read GetAsFloat write SetAsFloat;
  359. published
  360. property MaxValue: Extended read FMaxValue write FMaxValue;
  361. property MinValue: Extended read FMinValue write FMinValue;
  362. property Precision: Longint read FPrecision write FPrecision default 15;
  363. end;
  364. { TBooleanField }
  365. TBooleanField = class(TField)
  366. private
  367. FDisplayValues : String;
  368. // First byte indicates uppercase or not.
  369. FDisplays : Array[Boolean,Boolean] of string;
  370. Procedure SetDisplayValues(AValue : String);
  371. protected
  372. function GetAsBoolean: Boolean; override;
  373. function GetAsString: string; override;
  374. function GetDataSize: Word; override;
  375. function GetDefaultWidth: Longint; override;
  376. procedure SetAsBoolean(AValue: Boolean); override;
  377. procedure SetAsString(const AValue: string); override;
  378. public
  379. constructor Create(AOwner: TComponent); override;
  380. property Value: Boolean read GetAsBoolean write SetAsBoolean;
  381. published
  382. property DisplayValues: string read FDisplayValues write SetDisplayValues;
  383. end;
  384. { TDateTimeField }
  385. TDateTimeField = class(TField)
  386. private
  387. FDisplayFormat : String;
  388. protected
  389. function GetAsDateTime: TDateTime; override;
  390. function GetAsFloat: Extended; override;
  391. function GetAsString: string; override;
  392. function GetDataSize: Word; override;
  393. procedure GetText(var theText: string; ADisplayText: Boolean); override;
  394. procedure SetAsDateTime(AValue: TDateTime); override;
  395. procedure SetAsFloat(AValue: Extended); override;
  396. procedure SetAsString(const AValue: string); override;
  397. public
  398. constructor Create(AOwner: TComponent); override;
  399. property Value: TDateTime read GetAsDateTime write SetAsDateTime;
  400. published
  401. property DisplayFormat: string read FDisplayFormat write FDisplayFormat;
  402. end;
  403. { TDateField }
  404. TDateField = class(TDateTimeField)
  405. protected
  406. function GetDataSize: Word; override;
  407. public
  408. constructor Create(AOwner: TComponent); override;
  409. end;
  410. { TTimeField }
  411. TTimeField = class(TDateTimeField)
  412. protected
  413. function GetDataSize: Word; override;
  414. public
  415. constructor Create(AOwner: TComponent); override;
  416. end;
  417. { TBinaryField }
  418. TBinaryField = class(TField)
  419. protected
  420. class procedure CheckTypeSize(AValue: Longint); override;
  421. function GetAsString: string; override;
  422. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  423. procedure SetAsString(const AValue: string); override;
  424. procedure SetText(const AValue: string); override;
  425. public
  426. constructor Create(AOwner: TComponent); override;
  427. published
  428. property Size default 16;
  429. end;
  430. { TBytesField }
  431. TBytesField = class(TBinaryField)
  432. protected
  433. function GetDataSize: Word; override;
  434. public
  435. constructor Create(AOwner: TComponent); override;
  436. end;
  437. { TVarBytesField }
  438. TVarBytesField = class(TBytesField)
  439. protected
  440. function GetDataSize: Word; override;
  441. public
  442. constructor Create(AOwner: TComponent); override;
  443. end;
  444. { TBCDField }
  445. TBCDField = class(TNumericField)
  446. private
  447. protected
  448. class procedure CheckTypeSize(AValue: Longint); override;
  449. function GetAsFloat: Extended; override;
  450. function GetAsLongint: Longint; override;
  451. function GetAsString: string; override;
  452. function GetDataSize: Word; override;
  453. function GetDefaultWidth: Longint; override;
  454. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  455. procedure SetAsFloat(AValue: Extended); override;
  456. procedure SetAsLongint(AValue: Longint); override;
  457. procedure SetAsString(const AValue: string); override;
  458. public
  459. constructor Create(AOwner: TComponent); override;
  460. published
  461. property Size default 4;
  462. end;
  463. { TBlobField }
  464. TBlobStreamMode = (bmRead, bmWrite, bmReadWrite);
  465. TBlobType = ftBlob..ftTypedBinary;
  466. TBlobField = class(TField)
  467. private
  468. FBlobSize : Longint;
  469. FBlobType : TBlobType;
  470. FModified : Boolean;
  471. FTransliterate : Boolean;
  472. Function GetBlobStream (Mode : TBlobStreamMode) : TStream;
  473. protected
  474. procedure AssignTo(Dest: TPersistent); override;
  475. procedure FreeBuffers; override;
  476. function GetAsString: string; override;
  477. function GetBlobSize: Longint; virtual;
  478. function GetIsNull: Boolean; override;
  479. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  480. procedure SetAsString(const AValue: string); override;
  481. procedure SetText(const AValue: string); override;
  482. public
  483. constructor Create(AOwner: TComponent); override;
  484. procedure Assign(Source: TPersistent); override;
  485. procedure Clear; override;
  486. class function IsBlob: Boolean; override;
  487. procedure LoadFromFile(const FileName: string);
  488. procedure LoadFromStream(Stream: TStream);
  489. procedure SaveToFile(const FileName: string);
  490. procedure SaveToStream(Stream: TStream);
  491. procedure SetFieldType(AValue: TFieldType); override;
  492. property BlobSize: Longint read FBlobSize;
  493. property Modified: Boolean read FModified write FModified;
  494. property Value: string read GetAsString write SetAsString;
  495. property Transliterate: Boolean read FTransliterate write FTransliterate;
  496. published
  497. property BlobType: TBlobType read FBlobType write FBlobType;
  498. property Size default 0;
  499. end;
  500. { TMemoField }
  501. TMemoField = class(TBlobField)
  502. public
  503. constructor Create(AOwner: TComponent); override;
  504. published
  505. property Transliterate default True;
  506. end;
  507. { TGraphicField }
  508. TGraphicField = class(TBlobField)
  509. public
  510. constructor Create(AOwner: TComponent); override;
  511. end;
  512. { TIndexDef }
  513. TIndexDefs = class;
  514. TIndexOptions = set of (ixPrimary, ixUnique, ixDescending,
  515. ixCaseInsensitive, ixExpression);
  516. TIndexDef = class
  517. Private
  518. FExpression : String;
  519. FFields : String;
  520. FName : String;
  521. FOptions : TIndexOptions;
  522. FSource : String;
  523. public
  524. constructor Create(Owner: TIndexDefs; const AName, TheFields: string;
  525. TheOptions: TIndexOptions);
  526. destructor Destroy; override;
  527. property Expression: string read FExpression;
  528. property Fields: string read FFields;
  529. property Name: string read FName;
  530. property Options: TIndexOptions read FOptions;
  531. property Source: string read FSource write FSource;
  532. end;
  533. { TIndexDefs }
  534. TIndexDefs = class
  535. Private
  536. FCount : Longint;
  537. FUpDated : Boolean;
  538. Function GetItem (Index : longint) : TindexDef;
  539. public
  540. constructor Create(DataSet: TDataSet);
  541. destructor Destroy; override;
  542. procedure Add(const Name, Fields: string; Options: TIndexOptions);
  543. procedure Assign(IndexDefs: TIndexDefs);
  544. procedure Clear;
  545. function FindIndexForFields(const Fields: string): TIndexDef;
  546. function GetIndexForFields(const Fields: string;
  547. CaseInsensitive: Boolean): TIndexDef;
  548. function IndexOf(const Name: string): Longint;
  549. procedure Update;
  550. property Count: Longint read FCount;
  551. property Items[Index: Longint]: TIndexDef read GetItem; default;
  552. property Updated: Boolean read FUpdated write FUpdated;
  553. end;
  554. { TCheckConstraint }
  555. TCheckConstraint = class(TCollectionItem)
  556. Private
  557. FCustomConstraint : String;
  558. FErrorMessage : String;
  559. FFromDictionary : Boolean;
  560. FImportedConstraint : String;
  561. public
  562. procedure Assign(Source: TPersistent); override;
  563. // function GetDisplayName: string; override;
  564. published
  565. property CustomConstraint: string read FCustomConstraint write FCustomConstraint;
  566. property ErrorMessage: string read FErrorMessage write FErrorMessage;
  567. property FromDictionary: Boolean read FFromDictionary write FFromDictionary;
  568. property ImportedConstraint: string read FImportedConstraint write FImportedConstraint;
  569. end;
  570. { TCheckConstraints }
  571. TCheckConstraints = class(TCollection)
  572. Private
  573. Function GetItem(Index : Longint) : TCheckConstraint;
  574. Procedure SetItem(index : Longint; Value : TCheckConstraint);
  575. protected
  576. function GetOwner: TPersistent; override;
  577. public
  578. constructor Create(Owner: TPersistent);
  579. function Add: TCheckConstraint;
  580. property Items[Index: Longint]: TCheckConstraint read GetItem write SetItem; default;
  581. end;
  582. { TFields }
  583. Tfields = Class(TObject)
  584. Private
  585. FDataset : TDataset;
  586. FFieldList : TList;
  587. FOnChange : TNotifyEvent;
  588. FValidFieldKinds : TFieldKinds;
  589. Protected
  590. Procedure Changed;
  591. Procedure CheckfieldKind(Fieldkind : TFieldKind; Field : TField);
  592. Function GetCount : Longint;
  593. Function GetField (Index : longint) : TField;
  594. Procedure SetFieldIndex (Field : TField;Value : Integer);
  595. Property OnChange : TNotifyEvent Read FOnChange Write FOnChange;
  596. Property ValidFieldKinds : TFieldKinds Read FValidFieldKinds;
  597. Public
  598. Constructor Create(ADataset : TDataset);
  599. Destructor Destroy;override;
  600. Procedure Add(Field : TField);
  601. Procedure CheckFieldName (Const Value : String);
  602. Procedure CheckFieldNames (Const Value : String);
  603. Procedure Clear;
  604. Function FindField (Const Value : String) : TField;
  605. Function FieldByName (Const Value : String) : TField;
  606. Function FieldByNumber(FieldNo : Integer) : TField;
  607. Procedure GetFieldNames (Values : TStrings);
  608. Function IndexOf(Field : TField) : Longint;
  609. procedure Remove(Value : TField);
  610. Property Count : Integer Read GetCount;
  611. Property Dataset : TDataset Read FDataset;
  612. Property Fields [Index : Integer] : TField Read GetField; default;
  613. end;
  614. { TDataSet }
  615. TBookmark = Pointer;
  616. TBookmarkStr = string;
  617. PBookmarkFlag = ^TBookmarkFlag;
  618. TBookmarkFlag = (bfCurrent, bfBOF, bfEOF, bfInserted);
  619. PBufferList = ^TBufferList;
  620. TBufferList = array[0..dsMaxBufferCount - 1] of PChar;
  621. TGetMode = (gmCurrent, gmNext, gmPrior);
  622. TGetResult = (grOK, grBOF, grEOF, grError);
  623. TResyncMode = set of (rmExact, rmCenter);
  624. TDataAction = (daFail, daAbort, daRetry);
  625. TUpdateKind = (ukModify, ukInsert, ukDelete);
  626. TLocateOption = (loCaseInsensitive, loPartialKey);
  627. TLocateOptions = set of TLocateOption;
  628. TDataOperation = procedure of object;
  629. TDataSetNotifyEvent = procedure(DataSet: TDataSet) of object;
  630. TDataSetErrorEvent = procedure(DataSet: TDataSet; E: EDatabaseError;
  631. var Action: TDataAction) of object;
  632. TFilterOption = (foCaseInsensitive, foNoPartialCompare);
  633. TFilterOptions = set of TFilterOption;
  634. TFilterRecordEvent = procedure(DataSet: TDataSet;
  635. var Accept: Boolean) of object;
  636. TDatasetClass = Class of TDataset;
  637. TBufferArray = ^pchar;
  638. TDataSet = class(TComponent)
  639. Private
  640. FActive: Boolean;
  641. FActiveRecord: Longint;
  642. FAfterCancel: TDataSetNotifyEvent;
  643. FAfterClose: TDataSetNotifyEvent;
  644. FAfterDelete: TDataSetNotifyEvent;
  645. FAfterEdit: TDataSetNotifyEvent;
  646. FAfterInsert: TDataSetNotifyEvent;
  647. FAfterOpen: TDataSetNotifyEvent;
  648. FAfterPost: TDataSetNotifyEvent;
  649. FAfterScroll: TDataSetNotifyEvent;
  650. FAutoCalcFields: Boolean;
  651. FBOF: Boolean;
  652. FBeforeCancel: TDataSetNotifyEvent;
  653. FBeforeClose: TDataSetNotifyEvent;
  654. FBeforeDelete: TDataSetNotifyEvent;
  655. FBeforeEdit: TDataSetNotifyEvent;
  656. FBeforeInsert: TDataSetNotifyEvent;
  657. FBeforeOpen: TDataSetNotifyEvent;
  658. FBeforePost: TDataSetNotifyEvent;
  659. FBeforeScroll: TDataSetNotifyEvent;
  660. FBlobFieldCount: Longint;
  661. FBookmark: TBookmarkStr;
  662. FBookmarkSize: Longint;
  663. FBuffers : TBufferArray;
  664. FBufferCount: Longint;
  665. FCalcBuffer: PChar;
  666. FCalcFieldsSize: Longint;
  667. FCanModify: Boolean;
  668. FConstraints: TCheckConstraints;
  669. FDisableControlsCount : Integer;
  670. FDisableControlsState : TDatasetState;
  671. FCurrentRecord: Longint;
  672. FDataSources : TList;
  673. FDefaultFields: Boolean;
  674. FEOF: Boolean;
  675. FEnableControlsEvent : TDataEvent;
  676. FFieldList : TFields;
  677. FFieldCount : Longint;
  678. FFieldDefs: TFieldDefs;
  679. FFilterOptions: TFilterOptions;
  680. FFilterText: string;
  681. FFiltered: Boolean;
  682. FFound: Boolean;
  683. FInternalCalcFields: Boolean;
  684. FModified: Boolean;
  685. FOnCalcFields: TDataSetNotifyEvent;
  686. FOnDeleteError: TDataSetErrorEvent;
  687. FOnEditError: TDataSetErrorEvent;
  688. FOnFilterRecord: TFilterRecordEvent;
  689. FOnNewRecord: TDataSetNotifyEvent;
  690. FOnPostError: TDataSetErrorEvent;
  691. FRecNo: Longint;
  692. FRecordCount: Longint;
  693. FRecordSize: Word;
  694. FState : TDataSetState;
  695. Procedure DoInsertAppend(DoAppend : Boolean);
  696. Procedure DoInternalOpen;
  697. Procedure DoInternalClose;
  698. Function GetBuffer (Index : longint) : Pchar;
  699. Function GetField (Index : Longint) : TField;
  700. procedure RecalcBufListSize;
  701. Procedure RegisterDataSource(ADatasource : TDataSource);
  702. Procedure RemoveField (Field : TField);
  703. Procedure SetActive (Value : Boolean);
  704. procedure SetBufferCount(const AValue: Longint);
  705. Procedure SetField (Index : Longint;Value : TField);
  706. Procedure ShiftBuffers (Offset,Distance : Longint);
  707. Function TryDoing (P : TDataOperation; Ev : TDatasetErrorEvent) : Boolean;
  708. Procedure UnRegisterDataSource(ADatasource : TDatasource);
  709. Procedure UpdateFieldDefs;
  710. protected
  711. procedure ActivateBuffers; virtual;
  712. procedure BindFields(Binding: Boolean);
  713. function BookmarkAvailable: Boolean;
  714. procedure CalculateFields(Buffer: PChar); virtual;
  715. procedure CheckActive; virtual;
  716. procedure CheckInactive; virtual;
  717. procedure ClearBuffers; virtual;
  718. procedure ClearCalcFields(Buffer: PChar); virtual;
  719. procedure CloseBlob(Field: TField); virtual;
  720. procedure CloseCursor; virtual;
  721. procedure CreateFields;
  722. procedure DataEvent(Event: TDataEvent; Info: Longint); virtual;
  723. procedure DestroyFields; virtual;
  724. procedure DoAfterCancel; virtual;
  725. procedure DoAfterClose; virtual;
  726. procedure DoAfterDelete; virtual;
  727. procedure DoAfterEdit; virtual;
  728. procedure DoAfterInsert; virtual;
  729. procedure DoAfterOpen; virtual;
  730. procedure DoAfterPost; virtual;
  731. procedure DoAfterScroll; virtual;
  732. procedure DoBeforeCancel; virtual;
  733. procedure DoBeforeClose; virtual;
  734. procedure DoBeforeDelete; virtual;
  735. procedure DoBeforeEdit; virtual;
  736. procedure DoBeforeInsert; virtual;
  737. procedure DoBeforeOpen; virtual;
  738. procedure DoBeforePost; virtual;
  739. procedure DoBeforeScroll; virtual;
  740. procedure DoOnCalcFields; virtual;
  741. procedure DoOnNewRecord; virtual;
  742. function FieldByNumber(FieldNo: Longint): TField;
  743. function FindRecord(Restart, GoForward: Boolean): Boolean; virtual;
  744. procedure FreeFieldBuffers; virtual;
  745. function GetBookmarkStr: TBookmarkStr; virtual;
  746. procedure GetCalcFields(Buffer: PChar); virtual;
  747. function GetCanModify: Boolean; virtual;
  748. procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
  749. function GetFieldClass(FieldType: TFieldType): TFieldClass; virtual;
  750. Function GetfieldCount : Integer;
  751. function GetIsIndexField(Field: TField): Boolean; virtual;
  752. function GetNextRecords: Longint; virtual;
  753. function GetNextRecord: Boolean; virtual;
  754. function GetPriorRecords: Longint; virtual;
  755. function GetPriorRecord: Boolean; virtual;
  756. function GetRecordCount: Longint; virtual;
  757. function GetRecNo: Longint; virtual;
  758. procedure InitFieldDefs; virtual;
  759. procedure InitRecord(Buffer: PChar); virtual;
  760. procedure InternalCancel; virtual;
  761. procedure InternalEdit; virtual;
  762. procedure InternalRefresh; virtual;
  763. procedure Loaded; override;
  764. procedure OpenCursor(InfoQuery: Boolean); virtual;
  765. procedure RefreshInternalCalcFields(Buffer: PChar); virtual;
  766. Function RequiredBuffers : longint;
  767. procedure RestoreState(const Value: TDataSetState);
  768. procedure SetBookmarkStr(const Value: TBookmarkStr); virtual;
  769. procedure SetBufListSize(Value: Longint);
  770. procedure SetChildOrder(Component: TComponent; Order: Longint); override;
  771. procedure SetCurrentRecord(Index: Longint); virtual;
  772. procedure SetFiltered(Value: Boolean); virtual;
  773. procedure SetFilterOptions(Value: TFilterOptions); virtual;
  774. procedure SetFilterText(const Value: string); virtual;
  775. procedure SetFound(const Value: Boolean);
  776. procedure SetModified(Value: Boolean);
  777. procedure SetName(const Value: TComponentName); override;
  778. procedure SetOnFilterRecord(const Value: TFilterRecordEvent); virtual;
  779. procedure SetRecNo(Value: Longint); virtual;
  780. procedure SetState(Value: TDataSetState);
  781. function SetTempState(const Value: TDataSetState): TDataSetState;
  782. function TempBuffer: PChar;
  783. procedure UpdateIndexDefs; virtual;
  784. property ActiveRecord: Longint read FActiveRecord;
  785. property CurrentRecord: Longint read FCurrentRecord;
  786. property BlobFieldCount: Longint read FBlobFieldCount;
  787. property BookmarkSize: Longint read FBookmarkSize write FBookmarkSize;
  788. property Buffers[Index: Longint]: PChar read GetBuffer;
  789. property BufferCount: Longint read FBufferCount;
  790. property CalcBuffer: PChar read FCalcBuffer;
  791. property CalcFieldsSize: Longint read FCalcFieldsSize;
  792. property InternalCalcFields: Boolean read FInternalCalcFields;
  793. property Constraints: TCheckConstraints read FConstraints write FConstraints;
  794. protected { abstract methods }
  795. function AllocRecordBuffer: PChar; virtual; abstract;
  796. procedure FreeRecordBuffer(var Buffer: PChar); virtual; abstract;
  797. procedure GetBookmarkData(Buffer: PChar; Data: Pointer); virtual; abstract;
  798. function GetBookmarkFlag(Buffer: PChar): TBookmarkFlag; virtual; abstract;
  799. function GetFieldData(Field: TField; Buffer: Pointer): Boolean; virtual; abstract;
  800. function GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck: Boolean): TGetResult; virtual; abstract;
  801. function GetRecordSize: Word; virtual; abstract;
  802. procedure InternalAddRecord(Buffer: Pointer; Append: Boolean); virtual; abstract;
  803. procedure InternalClose; virtual; abstract;
  804. procedure InternalDelete; virtual; abstract;
  805. procedure InternalFirst; virtual; abstract;
  806. procedure InternalGotoBookmark(ABookmark: Pointer); virtual; abstract;
  807. procedure InternalHandleException; virtual; abstract;
  808. procedure InternalInitFieldDefs; virtual; abstract;
  809. procedure InternalInitRecord(Buffer: PChar); virtual; abstract;
  810. procedure InternalLast; virtual; abstract;
  811. procedure InternalOpen; virtual; abstract;
  812. procedure InternalPost; virtual; abstract;
  813. procedure InternalSetToRecord(Buffer: PChar); virtual; abstract;
  814. function IsCursorOpen: Boolean; virtual; abstract;
  815. procedure SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag); virtual; abstract;
  816. procedure SetBookmarkData(Buffer: PChar; Data: Pointer); virtual; abstract;
  817. procedure SetFieldData(Field: TField; Buffer: Pointer); virtual; abstract;
  818. public
  819. constructor Create(AOwner: TComponent); override;
  820. destructor Destroy; override;
  821. function ActiveBuffer: PChar;
  822. procedure Append;
  823. procedure AppendRecord(const Values: array of const);
  824. function BookmarkValid(ABookmark: TBookmark): Boolean; virtual;
  825. procedure Cancel; virtual;
  826. procedure CheckBrowseMode;
  827. procedure ClearFields;
  828. procedure Close;
  829. function ControlsDisabled: Boolean;
  830. function CompareBookmarks(Bookmark1, Bookmark2: TBookmark): Longint; virtual;
  831. function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; virtual;
  832. procedure CursorPosChanged;
  833. procedure Delete;
  834. procedure DisableControls;
  835. procedure Edit;
  836. procedure EnableControls;
  837. function FieldByName(const FieldName: string): TField;
  838. function FindField(const FieldName: string): TField;
  839. function FindFirst: Boolean;
  840. function FindLast: Boolean;
  841. function FindNext: Boolean;
  842. function FindPrior: Boolean;
  843. procedure First;
  844. procedure FreeBookmark(ABookmark: TBookmark); virtual;
  845. function GetBookmark: TBookmark; virtual;
  846. function GetCurrentRecord(Buffer: PChar): Boolean; virtual;
  847. procedure GetFieldList(List: TList; const FieldNames: string);
  848. procedure GetFieldNames(List: TStrings);
  849. procedure GotoBookmark(ABookmark: TBookmark);
  850. procedure Insert;
  851. procedure InsertRecord(const Values: array of const);
  852. function IsEmpty: Boolean;
  853. function IsSequenced: Boolean; virtual;
  854. procedure Last;
  855. function MoveBy(Distance: Longint): Longint;
  856. procedure Next;
  857. procedure Open;
  858. procedure Post; virtual;
  859. procedure Prior;
  860. procedure Refresh;
  861. procedure Resync(Mode: TResyncMode); virtual;
  862. procedure SetFields(const Values: array of const);
  863. procedure Translate(Src, Dest: PChar; ToOem: Boolean); virtual;
  864. procedure UpdateCursorPos;
  865. procedure UpdateRecord;
  866. property BOF: Boolean read FBOF;
  867. property Bookmark: TBookmarkStr read GetBookmarkStr write SetBookmarkStr;
  868. property CanModify: Boolean read GetCanModify;
  869. property DefaultFields: Boolean read FDefaultFields;
  870. property EOF: Boolean read FEOF;
  871. property FieldCount: Longint read GetFieldCount;
  872. property FieldDefs: TFieldDefs read FFieldDefs write FFieldDefs;
  873. property Fields[Index: Longint]: TField read GetField write SetField;
  874. property Found: Boolean read FFound;
  875. property Modified: Boolean read FModified;
  876. property RecordCount: Longint read GetRecordCount;
  877. property RecNo: Longint read FRecNo write FRecNo;
  878. property RecordSize: Word read FRecordSize;
  879. property State: TDataSetState read FState;
  880. // property Fields : TFields Read FFieldList;
  881. property Filter: string read FFilterText write FFilterText;
  882. property Filtered: Boolean read FFiltered write FFiltered default False;
  883. property FilterOptions: TFilterOptions read FFilterOptions write FFilterOptions;
  884. property Active: Boolean read FActive write SetActive default False;
  885. property AutoCalcFields: Boolean read FAutoCalcFields write FAutoCalcFields;
  886. property BeforeOpen: TDataSetNotifyEvent read FBeforeOpen write FBeforeOpen;
  887. property AfterOpen: TDataSetNotifyEvent read FAfterOpen write FAfterOpen;
  888. property BeforeClose: TDataSetNotifyEvent read FBeforeClose write FBeforeClose;
  889. property AfterClose: TDataSetNotifyEvent read FAfterClose write FAfterClose;
  890. property BeforeInsert: TDataSetNotifyEvent read FBeforeInsert write FBeforeInsert;
  891. property AfterInsert: TDataSetNotifyEvent read FAfterInsert write FAfterInsert;
  892. property BeforeEdit: TDataSetNotifyEvent read FBeforeEdit write FBeforeEdit;
  893. property AfterEdit: TDataSetNotifyEvent read FAfterEdit write FAfterEdit;
  894. property BeforePost: TDataSetNotifyEvent read FBeforePost write FBeforePost;
  895. property AfterPost: TDataSetNotifyEvent read FAfterPost write FAfterPost;
  896. property BeforeCancel: TDataSetNotifyEvent read FBeforeCancel write FBeforeCancel;
  897. property AfterCancel: TDataSetNotifyEvent read FAfterCancel write FAfterCancel;
  898. property BeforeDelete: TDataSetNotifyEvent read FBeforeDelete write FBeforeDelete;
  899. property AfterDelete: TDataSetNotifyEvent read FAfterDelete write FAfterDelete;
  900. property BeforeScroll: TDataSetNotifyEvent read FBeforeScroll write FBeforeScroll;
  901. property AfterScroll: TDataSetNotifyEvent read FAfterScroll write FAfterScroll;
  902. property OnCalcFields: TDataSetNotifyEvent read FOnCalcFields write FOnCalcFields;
  903. property OnDeleteError: TDataSetErrorEvent read FOnDeleteError write FOnDeleteError;
  904. property OnEditError: TDataSetErrorEvent read FOnEditError write FOnEditError;
  905. property OnFilterRecord: TFilterRecordEvent read FOnFilterRecord write SetOnFilterRecord;
  906. property OnNewRecord: TDataSetNotifyEvent read FOnNewRecord write FOnNewRecord;
  907. property OnPostError: TDataSetErrorEvent read FOnPostError write FOnPostError;
  908. end;
  909. TDataLink = class(TPersistent)
  910. private
  911. FFIrstRecord,
  912. FBufferCount : Integer;
  913. FActive,
  914. FDataSourceFixed,
  915. FEditing,
  916. FReadOnly,
  917. FUpdatingRecord,
  918. FVisualControl : Boolean;
  919. FDataSource : TDataSource;
  920. Function CalcFirstRecord(Index : Integer) : Integer;
  921. Procedure CalcRange;
  922. Procedure CheckActiveAndEditing;
  923. Function GetDataset : TDataset;
  924. procedure SetActive(AActive: Boolean);
  925. procedure SetDataSource(Value: TDataSource);
  926. Procedure SetReadOnly(Value : Boolean);
  927. protected
  928. procedure ActiveChanged; virtual;
  929. procedure CheckBrowseMode; virtual;
  930. procedure DataEvent(Event: TDataEvent; Info: Longint); virtual;
  931. procedure DataSetChanged; virtual;
  932. procedure DataSetScrolled(Distance: Integer); virtual;
  933. procedure EditingChanged; virtual;
  934. procedure FocusControl(Field: TFieldRef); virtual;
  935. function GetActiveRecord: Integer; virtual;
  936. function GetBOF: Boolean; virtual;
  937. function GetBufferCount: Integer; virtual;
  938. function GetEOF: Boolean; virtual;
  939. function GetRecordCount: Integer; virtual;
  940. procedure LayoutChanged; virtual;
  941. function MoveBy(Distance: Integer): Integer; virtual;
  942. procedure RecordChanged(Field: TField); virtual;
  943. procedure SetActiveRecord(Value: Integer); virtual;
  944. procedure SetBufferCount(Value: Integer); virtual;
  945. procedure UpdateData; virtual;
  946. property VisualControl: Boolean read FVisualControl write FVisualControl;
  947. public
  948. constructor Create;
  949. destructor Destroy; override;
  950. function Edit: Boolean;
  951. procedure UpdateRecord;
  952. property Active: Boolean read FActive;
  953. property ActiveRecord: Integer read GetActiveRecord write SetActiveRecord;
  954. property BOF: Boolean read GetBOF;
  955. property BufferCount: Integer read FBufferCount write SetBufferCount;
  956. property DataSet: TDataSet read GetDataSet;
  957. property DataSource: TDataSource read FDataSource write SetDataSource;
  958. property DataSourceFixed: Boolean read FDataSourceFixed write FDataSourceFixed;
  959. property Editing: Boolean read FEditing;
  960. property Eof: Boolean read GetEOF;
  961. property ReadOnly: Boolean read FReadOnly write SetReadOnly;
  962. property RecordCount: Integer read GetRecordCount;
  963. end;
  964. { TDetailDataLink }
  965. TDetailDataLink = class(TDataLink)
  966. protected
  967. function GetDetailDataSet: TDataSet; virtual;
  968. public
  969. property DetailDataSet: TDataSet read GetDetailDataSet;
  970. end;
  971. { TMasterDataLink }
  972. TMasterDataLink = class(TDetailDataLink)
  973. private
  974. FDataSet: TDataSet;
  975. FFieldNames: string;
  976. FFields: TList;
  977. FOnMasterChange: TNotifyEvent;
  978. FOnMasterDisable: TNotifyEvent;
  979. procedure SetFieldNames(const Value: string);
  980. protected
  981. procedure ActiveChanged; override;
  982. procedure CheckBrowseMode; override;
  983. function GetDetailDataSet: TDataSet; override;
  984. procedure LayoutChanged; override;
  985. procedure RecordChanged(Field: TField); override;
  986. public
  987. constructor Create(ADataSet: TDataSet);
  988. destructor Destroy; override;
  989. property FieldNames: string read FFieldNames write SetFieldNames;
  990. property Fields: TList read FFields;
  991. property OnMasterChange: TNotifyEvent read FOnMasterChange write FOnMasterChange;
  992. property OnMasterDisable: TNotifyEvent read FOnMasterDisable write FOnMasterDisable;
  993. end;
  994. { TDataSource }
  995. TDataChangeEvent = procedure(Sender: TObject; Field: TField) of object;
  996. TDataSource = class(TComponent)
  997. private
  998. FDataSet: TDataSet;
  999. FDataLinks: TList;
  1000. FEnabled: Boolean;
  1001. FAutoEdit: Boolean;
  1002. FState: TDataSetState;
  1003. FOnStateChange: TNotifyEvent;
  1004. FOnDataChange: TDataChangeEvent;
  1005. FOnUpdateData: TNotifyEvent;
  1006. procedure DistributeEvent(Event: TDataEvent; Info: Longint);
  1007. procedure RegisterDataLink(DataLink: TDataLink);
  1008. Procedure ProcessEvent(Event : TDataEvent; Info : longint);
  1009. procedure SetDataSet(ADataSet: TDataSet);
  1010. procedure SetEnabled(Value: Boolean);
  1011. procedure UnregisterDataLink(DataLink: TDataLink);
  1012. protected
  1013. Procedure DoDataChange (Info : Pointer);virtual;
  1014. Procedure DoStateChange; virtual;
  1015. Procedure DoUpdateData;
  1016. property DataLinks: TList read FDataLinks;
  1017. public
  1018. constructor Create(AOwner: TComponent); override;
  1019. destructor Destroy; override;
  1020. procedure Edit;
  1021. function IsLinkedTo(ADataSet: TDataSet): Boolean;
  1022. property State: TDataSetState read FState;
  1023. published
  1024. property AutoEdit: Boolean read FAutoEdit write FAutoEdit default True;
  1025. property DataSet: TDataSet read FDataSet write SetDataSet;
  1026. property Enabled: Boolean read FEnabled write SetEnabled default True;
  1027. property OnStateChange: TNotifyEvent read FOnStateChange write FOnStateChange;
  1028. property OnDataChange: TDataChangeEvent read FOnDataChange write FOnDataChange;
  1029. property OnUpdateData: TNotifyEvent read FOnUpdateData write FOnUpdateData;
  1030. end;
  1031. { TDBDataset }
  1032. TDBDatasetClass = Class of TDBDataset;
  1033. TDBDataset = Class(TDataset)
  1034. Private
  1035. FDatabase : TDatabase;
  1036. Procedure SetDatabase (Value : TDatabase);
  1037. Protected
  1038. Procedure CheckDatabase;
  1039. Public
  1040. Destructor destroy; override;
  1041. Property DataBase : TDatabase Read FDatabase Write SetDatabase;
  1042. end;
  1043. { TDatabase }
  1044. TLoginEvent = procedure(Database: TDatabase;
  1045. LoginParams: TStrings) of object;
  1046. TDatabaseClass = Class Of TDatabase;
  1047. TDatabase = class(TComponent)
  1048. private
  1049. FConnected : Boolean;
  1050. FDataBaseName : String;
  1051. FDataSets : TList;
  1052. FDirectory : String;
  1053. FKeepConnection : Boolean;
  1054. FLoginPrompt : Boolean;
  1055. FOnLogin : TLoginEvent;
  1056. FParams : TStrings;
  1057. FSQLBased : Boolean;
  1058. Function GetDataSetCount : Longint;
  1059. Function GetDataset(Index : longint) : TDBDataset;
  1060. procedure SetConnected (Value : boolean);
  1061. procedure RegisterDataset (DS : TDBDataset);
  1062. procedure UnRegisterDataset (DS : TDBDataset);
  1063. procedure RemoveDataSets;
  1064. protected
  1065. Procedure CheckConnected;
  1066. Procedure CheckDisConnected;
  1067. procedure Loaded; override;
  1068. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  1069. Procedure DoInternalConnect; Virtual;Abstract;
  1070. Procedure DoInternalDisConnect; Virtual;Abstract;
  1071. public
  1072. constructor Create(AOwner: TComponent); override;
  1073. destructor Destroy; override;
  1074. procedure Close;
  1075. procedure Open;
  1076. procedure CloseDataSets;
  1077. procedure StartTransaction; virtual; abstract;
  1078. procedure EndTransaction; virtual; abstract;
  1079. property DataSetCount: Longint read GetDataSetCount;
  1080. property DataSets[Index: Longint]: TDBDataSet read GetDataSet;
  1081. property Directory: string read FDirectory write FDirectory;
  1082. property IsSQLBased: Boolean read FSQLBased;
  1083. published
  1084. property Connected: Boolean read FConnected write SetConnected;
  1085. property DatabaseName: string read FDatabaseName write FDatabaseName;
  1086. property KeepConnection: Boolean read FKeepConnection write FKeepConnection;
  1087. property LoginPrompt: Boolean read FLoginPrompt write FLoginPrompt;
  1088. property Params : TStrings read FParams Write FParams;
  1089. property OnLogin: TLoginEvent read FOnLogin write FOnLogin;
  1090. end;
  1091. Const
  1092. Fieldtypenames : Array [TFieldType] of String[15] =
  1093. (
  1094. 'Unknown',
  1095. 'String',
  1096. 'Smallint',
  1097. 'Integer',
  1098. 'Word',
  1099. 'Boolean',
  1100. 'Float',
  1101. 'Currency',
  1102. 'BCD',
  1103. 'Date',
  1104. 'Time',
  1105. 'DateTime',
  1106. 'Bytes',
  1107. 'VarBytes',
  1108. 'AutoInc',
  1109. 'Blob',
  1110. 'Memo',
  1111. 'Graphic',
  1112. 'FmtMemo',
  1113. 'ParadoxOle',
  1114. 'DBaseOle',
  1115. 'TypedBinary',
  1116. 'Cursor',
  1117. 'FixedChar',
  1118. 'WideString',
  1119. 'Largeint',
  1120. 'ADT',
  1121. 'Array',
  1122. 'Reference',
  1123. 'DataSet',
  1124. 'OraBlob',
  1125. 'OraClob',
  1126. 'Variant',
  1127. 'Interface',
  1128. 'IDispatch',
  1129. 'Guid',
  1130. 'TimeStamp',
  1131. 'FMTBcd'
  1132. );
  1133. { 'Unknown',
  1134. 'String',
  1135. 'Smallint',
  1136. 'Integer',
  1137. 'Word',
  1138. 'Boolean',
  1139. 'Float',
  1140. 'Date',
  1141. 'Time',
  1142. 'DateTime',
  1143. 'Bytes',
  1144. 'VarBytes',
  1145. 'AutoInc',
  1146. 'Blob',
  1147. 'Memo',
  1148. 'Graphic',
  1149. 'FmtMemo',
  1150. 'ParadoxOle',
  1151. 'DBaseOle',
  1152. 'TypedBinary',
  1153. 'Cursor'
  1154. );}
  1155. dsEditModes = [dsEdit, dsInsert];
  1156. { Auxiliary functions }
  1157. Procedure DatabaseError (Const Msg : String);
  1158. Procedure DatabaseError (Const Msg : String; Comp : TComponent);
  1159. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of Const);
  1160. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of const;
  1161. Comp : TComponent);
  1162. implementation
  1163. { ---------------------------------------------------------------------
  1164. Auxiliary functions
  1165. ---------------------------------------------------------------------}
  1166. Procedure DatabaseError (Const Msg : String);
  1167. begin
  1168. Raise EDataBaseError.Create(Msg);
  1169. end;
  1170. Procedure DatabaseError (Const Msg : String; Comp : TComponent);
  1171. begin
  1172. Raise EDatabaseError.CreateFmt('%s : %s',[Comp.Name,Msg]);
  1173. end;
  1174. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of Const);
  1175. begin
  1176. Raise EDatabaseError.CreateFmt(Fmt,Args);
  1177. end;
  1178. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of const;
  1179. Comp : TComponent);
  1180. begin
  1181. Raise EDatabaseError.CreateFmt(Format('%s : %s',[Comp.Name,Fmt]),Args);
  1182. end;
  1183. {$i dbs.inc}
  1184. { TIndexDef }
  1185. constructor TIndexDef.Create(Owner: TIndexDefs; const AName, TheFields: string;
  1186. TheOptions: TIndexOptions);
  1187. begin
  1188. //!! To be implemented
  1189. end;
  1190. destructor TIndexDef.Destroy;
  1191. begin
  1192. //!! To be implemented
  1193. end;
  1194. { TIndexDefs }
  1195. Function TIndexDefs.GetItem (Index : longint) : TindexDef;
  1196. begin
  1197. //!! To be implemented
  1198. end;
  1199. constructor TIndexDefs.Create(DataSet: TDataSet);
  1200. begin
  1201. //!! To be implemented
  1202. end;
  1203. destructor TIndexDefs.Destroy;
  1204. begin
  1205. //!! To be implemented
  1206. end;
  1207. procedure TIndexDefs.Add(const Name, Fields: string; Options: TIndexOptions);
  1208. begin
  1209. //!! To be implemented
  1210. end;
  1211. procedure TIndexDefs.Assign(IndexDefs: TIndexDefs);
  1212. begin
  1213. //!! To be implemented
  1214. end;
  1215. procedure TIndexDefs.Clear;
  1216. begin
  1217. //!! To be implemented
  1218. end;
  1219. function TIndexDefs.FindIndexForFields(const Fields: string): TIndexDef;
  1220. begin
  1221. //!! To be implemented
  1222. end;
  1223. function TIndexDefs.GetIndexForFields(const Fields: string;
  1224. CaseInsensitive: Boolean): TIndexDef;
  1225. begin
  1226. //!! To be implemented
  1227. end;
  1228. function TIndexDefs.IndexOf(const Name: string): Longint;
  1229. begin
  1230. //!! To be implemented
  1231. end;
  1232. procedure TIndexDefs.Update;
  1233. begin
  1234. //!! To be implemented
  1235. end;
  1236. { TCheckConstraint }
  1237. procedure TCheckConstraint.Assign(Source: TPersistent);
  1238. begin
  1239. //!! To be implemented
  1240. end;
  1241. { TCheckConstraints }
  1242. Function TCheckConstraints.GetItem(Index : Longint) : TCheckConstraint;
  1243. begin
  1244. //!! To be implemented
  1245. end;
  1246. Procedure TCheckConstraints.SetItem(index : Longint; Value : TCheckConstraint);
  1247. begin
  1248. //!! To be implemented
  1249. end;
  1250. function TCheckConstraints.GetOwner: TPersistent;
  1251. begin
  1252. //!! To be implemented
  1253. end;
  1254. constructor TCheckConstraints.Create(Owner: TPersistent);
  1255. begin
  1256. //!! To be implemented
  1257. end;
  1258. function TCheckConstraints.Add: TCheckConstraint;
  1259. begin
  1260. //!! To be implemented
  1261. end;
  1262. {$i dataset.inc}
  1263. {$i fields.inc}
  1264. {$i datasource.inc}
  1265. {$i database.inc}
  1266. end.
  1267. {
  1268. $Log$
  1269. Revision 1.11 2003-10-06 17:04:27 florian
  1270. * small step towards calculated fields
  1271. Revision 1.10 2003/08/16 16:42:21 michael
  1272. + Fixes in TDBDataset etc. Changed MySQLDb to use database as well
  1273. Revision 1.9 2003/05/15 15:15:15 michael
  1274. + Database class in TDBDataset is public, not published
  1275. Revision 1.8 2003/05/08 21:52:41 michael
  1276. + Patch from Jesus Reyes
  1277. Revision 1.7 2003/02/20 19:30:28 michael
  1278. + Fixes from Jesus Reyes
  1279. Revision 1.6 2002/09/07 15:15:23 peter
  1280. * old logs removed and tabs fixed
  1281. }