dataset.inc 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875
  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. Dataset implementation
  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. { ---------------------------------------------------------------------
  14. TDataSet
  15. ---------------------------------------------------------------------}
  16. Const
  17. DefaultBufferCount = 10;
  18. constructor TDataSet.Create(AOwner: TComponent);
  19. begin
  20. Inherited Create(AOwner);
  21. FFieldDefs:=TFieldDefs.Create(Self);
  22. FFieldList:=TFields.Create(Self);
  23. FDataSources:=TList.Create;
  24. end;
  25. destructor TDataSet.Destroy;
  26. var
  27. i: Integer;
  28. begin
  29. Active:=False;
  30. FFieldDefs.Free;
  31. FFieldList.Free;
  32. With FDatasources do
  33. begin
  34. While Count>0 do
  35. TDatasource(Items[Count - 1]).DataSet:=Nil;
  36. Free;
  37. end;
  38. if Assigned(FBuffers) then
  39. begin
  40. for i := 0 to FBufferCount do
  41. FreeRecordBuffer(FBuffers[i]);
  42. FreeMem(FBuffers);
  43. end;
  44. Inherited Destroy;
  45. end;
  46. // This procedure must be called when the first record is made/read
  47. Procedure TDataset.ActivateBuffers;
  48. begin
  49. FBOF:=False;
  50. FEOF:=False;
  51. FActiveRecord:=0;
  52. end;
  53. Procedure TDataset.UpdateFieldDefs;
  54. begin
  55. //!! To be implemented
  56. end;
  57. Procedure TDataset.BindFields(Binding: Boolean);
  58. // Var I : longint;
  59. begin
  60. {
  61. Here some magic will be needed later; for now just simply set
  62. Just set fieldno from listindex...
  63. Later we should take it from the fielddefs.
  64. // ATM Set by CreateField ...
  65. For I:=0 to FFieldList.Count-1 do
  66. FFieldList[i].FFieldNo:=I;
  67. }
  68. end;
  69. Function TDataset.BookmarkAvailable: Boolean;
  70. Const BookmarkStates = [dsBrowse,dsEdit,dsInsert];
  71. begin
  72. Result:=(Not IsEmpty) and (State in BookmarkStates)
  73. and (getBookMarkFlag(ActiveBuffer)=bfCurrent);
  74. end;
  75. Procedure TDataset.CalculateFields(Buffer: PChar);
  76. begin
  77. { no internal calced fields or caches yet }
  78. DoOnCalcFields;
  79. end;
  80. Procedure TDataset.CheckActive;
  81. begin
  82. If Not Active then
  83. DataBaseError(SInactiveDataset);
  84. end;
  85. Procedure TDataset.CheckInactive;
  86. begin
  87. If Active then
  88. DataBaseError(SActiveDataset);
  89. end;
  90. Procedure TDataset.ClearBuffers;
  91. begin
  92. FRecordCount:=0;
  93. FactiveRecord:=0;
  94. FCurrentRecord:=-1;
  95. FBOF:=True;
  96. FEOF:=True;
  97. end;
  98. Procedure TDataset.ClearCalcFields(Buffer: PChar);
  99. begin
  100. //!! To be implemented
  101. end;
  102. Procedure TDataset.CloseBlob(Field: TField);
  103. begin
  104. //!! To be implemented
  105. end;
  106. Procedure TDataset.CloseCursor;
  107. begin
  108. //!! To be implemented
  109. end;
  110. Procedure TDataset.CreateFields;
  111. Var I : longint;
  112. begin
  113. {$ifdef DSDebug}
  114. Writeln ('Creating fields');
  115. Writeln ('Count : ',fielddefs.Count);
  116. For I:=0 to FieldDefs.Count-1 do
  117. Writeln('Def ',I,' : ',Fielddefs.items[i].Name,'(',Fielddefs.items[i].FieldNo,')');
  118. {$endif}
  119. For I:=0 to fielddefs.Count-1 do
  120. With Fielddefs.Items[I] do
  121. If DataType<>ftUnknown then
  122. begin
  123. {$ifdef DSDebug}
  124. Writeln('About to create field',FieldDefs.Items[i].Name);
  125. {$endif}
  126. CreateField(self);
  127. end;
  128. end;
  129. Procedure TDataset.DataEvent(Event: TDataEvent; Info: Ptrint);
  130. Var
  131. i : longint;
  132. begin
  133. // Do some bookkeeping;
  134. case Event of
  135. deFieldChange :
  136. begin
  137. if TField(Info).FieldKind in [fkData,fkInternalCalc] then
  138. SetModified(True);
  139. if FInternalCalcFields and (TField(Info).FieldKind = fkData) then
  140. RefreshInternalCalcFields(ActiveBuffer)
  141. else if (FCalcFieldsSize <> 0) and FAutoCalcFields and
  142. (TField(Info).FieldKind = fkData) then
  143. CalculateFields(ActiveBuffer);
  144. TField(Info).Change;
  145. end;
  146. end;
  147. // Distribute event to datasets;
  148. if FDisableControlsCount = 0 then
  149. for I := 0 to FDataSources.Count - 1 do
  150. TDataSource(FDataSources[I]).ProcessEvent(Event, Info);
  151. end;
  152. Procedure TDataset.DestroyFields;
  153. begin
  154. FFieldList.Clear;
  155. end;
  156. Procedure TDataset.DoAfterCancel;
  157. begin
  158. If assigned(FAfterCancel) then
  159. FAfterCancel(Self);
  160. end;
  161. Procedure TDataset.DoAfterClose;
  162. begin
  163. If assigned(FAfterClose) then
  164. FAfterClose(Self);
  165. end;
  166. Procedure TDataset.DoAfterDelete;
  167. begin
  168. If assigned(FAfterDelete) then
  169. FAfterDelete(Self);
  170. end;
  171. Procedure TDataset.DoAfterEdit;
  172. begin
  173. If assigned(FAfterEdit) then
  174. FAfterEdit(Self);
  175. end;
  176. Procedure TDataset.DoAfterInsert;
  177. begin
  178. If assigned(FAfterInsert) then
  179. FAfterInsert(Self);
  180. end;
  181. Procedure TDataset.DoAfterOpen;
  182. begin
  183. If assigned(FAfterOpen) then
  184. FAfterOpen(Self);
  185. end;
  186. Procedure TDataset.DoAfterPost;
  187. begin
  188. If assigned(FAfterPost) then
  189. FAfterPost(Self);
  190. end;
  191. Procedure TDataset.DoAfterScroll;
  192. begin
  193. If assigned(FAfterScroll) then
  194. FAfterScroll(Self);
  195. end;
  196. Procedure TDataset.DoBeforeCancel;
  197. begin
  198. If assigned(FBeforeCancel) then
  199. FBeforeCancel(Self);
  200. end;
  201. Procedure TDataset.DoBeforeClose;
  202. begin
  203. If assigned(FBeforeClose) then
  204. FBeforeClose(Self);
  205. end;
  206. Procedure TDataset.DoBeforeDelete;
  207. begin
  208. If assigned(FBeforeDelete) then
  209. FBeforeDelete(Self);
  210. end;
  211. Procedure TDataset.DoBeforeEdit;
  212. begin
  213. If assigned(FBeforeEdit) then
  214. FBeforeEdit(Self);
  215. end;
  216. Procedure TDataset.DoBeforeInsert;
  217. begin
  218. If assigned(FBeforeInsert) then
  219. FBeforeInsert(Self);
  220. end;
  221. Procedure TDataset.DoBeforeOpen;
  222. begin
  223. If assigned(FBeforeOpen) then
  224. FBeforeOpen(Self);
  225. end;
  226. Procedure TDataset.DoBeforePost;
  227. begin
  228. If assigned(FBeforePost) then
  229. FBeforePost(Self);
  230. end;
  231. Procedure TDataset.DoBeforeScroll;
  232. begin
  233. If assigned(FBeforeScroll) then
  234. FBeforeScroll(Self);
  235. end;
  236. Procedure TDataset.DoInternalOpen;
  237. begin
  238. FDefaultFields:=FieldCount=0;
  239. DoBeforeOpen;
  240. Try
  241. {$ifdef dsdebug}
  242. Writeln ('Calling internal open');
  243. {$endif}
  244. InternalOpen;
  245. FBOF:=True;
  246. {$ifdef dsdebug}
  247. Writeln ('Calling RecalcBufListSize');
  248. {$endif}
  249. FRecordcount := 0;
  250. RecalcBufListSize;
  251. FEOF := (FRecordcount = 0);
  252. {$ifdef dsdebug}
  253. Writeln ('Setting state to browse');
  254. {$endif}
  255. SetState(dsBrowse);
  256. DoAfterOpen;
  257. DoAfterScroll;
  258. except
  259. DoInternalClose(false);
  260. raise;
  261. end;
  262. end;
  263. Procedure TDataset.DoInternalClose(DoCheck : Boolean);
  264. begin
  265. if DoCheck then
  266. CheckBrowsemode;
  267. FreeFieldBuffers;
  268. ClearBuffers;
  269. SetBufListSize(-1);
  270. SetState(dsInactive);
  271. InternalClose;
  272. end;
  273. Procedure TDataset.DoOnCalcFields;
  274. begin
  275. If assigned(FOnCalcfields) then
  276. FOnCalcFields(Self);
  277. end;
  278. Procedure TDataset.DoOnNewRecord;
  279. begin
  280. If assigned(FOnNewRecord) then
  281. FOnNewRecord(Self);
  282. end;
  283. Function TDataset.FieldByNumber(FieldNo: Longint): TField;
  284. begin
  285. Result:=FFieldList.FieldByNumber(FieldNo);
  286. end;
  287. Function TDataset.FindRecord(Restart, GoForward: Boolean): Boolean;
  288. begin
  289. //!! To be implemented
  290. end;
  291. Procedure TDataset.FreeFieldBuffers;
  292. Var I : longint;
  293. begin
  294. For I:=0 to FFieldList.Count-1 do
  295. FFieldList[i].FreeBuffers;
  296. end;
  297. Function TDataset.GetBookmarkStr: TBookmarkStr;
  298. begin
  299. Result:='';
  300. If BookMarkAvailable then
  301. begin
  302. SetLength(Result,FBookMarkSize);
  303. GetBookMarkData(ActiveBuffer,Pointer(Result));
  304. end
  305. end;
  306. Function TDataset.GetBuffer (Index : longint) : Pchar;
  307. begin
  308. Result:=FBuffers[Index];
  309. end;
  310. Procedure TDataset.GetCalcFields(Buffer: PChar);
  311. begin
  312. //!! To be implemented
  313. end;
  314. Function TDataset.GetCanModify: Boolean;
  315. begin
  316. Result:= not FIsUnidirectional;
  317. end;
  318. Procedure TDataset.GetChildren(Proc: TGetChildProc; Root: TComponent);
  319. begin
  320. //!! To be implemented
  321. end;
  322. Function TDataset.GetDataSource: TDataSource;
  323. begin
  324. Result:=nil;
  325. end;
  326. Function TDataset.GetField (Index : Longint) : TField;
  327. begin
  328. Result:=FFIeldList[index];
  329. end;
  330. {
  331. This is not yet allowed, FPC doesn't allow typed consts of Classes...
  332. Const
  333. DefFieldClasses : Array [TFieldType] of TFieldClass =
  334. ( { ftUnknown} Tfield,
  335. { ftString} TStringField,
  336. { ftSmallint} TLongIntField,
  337. { ftInteger} TLongintField,
  338. { ftWord} TLongintField,
  339. { ftBoolean} TBooleanField,
  340. { ftFloat} TFloatField,
  341. { ftDate} TDateField,
  342. { ftTime} TTimeField,
  343. { ftDateTime} TDateTimeField,
  344. { ftBytes} TBytesField,
  345. { ftVarBytes} TVarBytesField,
  346. { ftAutoInc} TAutoIncField,
  347. { ftBlob} TBlobField,
  348. { ftMemo} TMemoField,
  349. { ftGraphic} TGraphicField,
  350. { ftFmtMemo} TMemoField,
  351. { ftParadoxOle} Nil,
  352. { ftDBaseOle} Nil,
  353. { ftTypedBinary} Nil,
  354. { ftCursor} Nil
  355. );
  356. }
  357. Function TDataset.GetFieldClass(FieldType: TFieldType): TFieldClass;
  358. begin
  359. Case FieldType of
  360. ftUnknown : Result:=Tfield;
  361. ftString: Result := TStringField;
  362. ftLargeint: Result := TLargeintField;
  363. ftSmallint: Result := TSmallIntField;
  364. ftInteger: Result := TLongintField;
  365. ftWord: Result := TWordField;
  366. ftBoolean: Result := TBooleanField;
  367. ftFloat: Result := TFloatField;
  368. ftBCD: Result := TBCDField;
  369. ftDate: Result := TDateField;
  370. ftTime: Result := TTimeField;
  371. ftDateTime: Result := TDateTimeField;
  372. ftBytes: Result := TBytesField;
  373. ftVarBytes: Result := TVarBytesField;
  374. ftAutoInc: Result := TAutoIncField;
  375. ftBlob: Result := TBlobField;
  376. ftMemo: Result := TMemoField;
  377. ftGraphic: Result := TGraphicField;
  378. ftFmtMemo: Result := TMemoField;
  379. ftParadoxOle: Result := Nil;
  380. ftDBaseOle: Result := Nil;
  381. ftTypedBinary: Result := Nil;
  382. ftCursor: Result := Nil
  383. else
  384. Result := nil;
  385. end;
  386. end;
  387. Function TDataset.GetIsIndexField(Field: TField): Boolean;
  388. begin
  389. //!! To be implemented
  390. end;
  391. Function TDataset.GetNextRecord: Boolean;
  392. procedure ExchangeBuffers(var buf1,buf2 : pointer);
  393. var tempbuf : pointer;
  394. begin
  395. tempbuf := buf1;
  396. buf1 := buf2;
  397. buf2 := tempbuf;
  398. end;
  399. begin
  400. {$ifdef dsdebug}
  401. Writeln ('Getting next record. Internal RecordCount : ',FRecordCount);
  402. {$endif}
  403. If FRecordCount>0 Then SetCurrentRecord(FRecordCount-1);
  404. Result:=GetRecord(FBuffers[FBuffercount],gmNext,True)=grOK;
  405. if result then
  406. begin
  407. If FRecordCount=0 then ActivateBuffers;
  408. if FRecordcount=FBuffercount then
  409. shiftbuffersbackward
  410. else
  411. begin
  412. inc(FRecordCount);
  413. FCurrentRecord:=FRecordCount - 1;
  414. ExchangeBuffers(Fbuffers[FCurrentRecord],FBuffers[FBuffercount]);
  415. end;
  416. end
  417. else
  418. cursorposchanged;
  419. {$ifdef dsdebug}
  420. Writeln ('Result getting next record : ',Result);
  421. {$endif}
  422. end;
  423. Function TDataset.GetNextRecords: Longint;
  424. begin
  425. Result:=0;
  426. {$ifdef dsdebug}
  427. Writeln ('Getting next record(s), need :',FBufferCount);
  428. {$endif}
  429. While (FRecordCount<FBufferCount) and GetNextRecord do
  430. Inc(Result);
  431. {$ifdef dsdebug}
  432. Writeln ('Result Getting next record(S), GOT :',RESULT);
  433. {$endif}
  434. end;
  435. Function TDataset.GetPriorRecord: Boolean;
  436. begin
  437. {$ifdef dsdebug}
  438. Writeln ('GetPriorRecord: Getting previous record');
  439. {$endif}
  440. If FRecordCount>0 Then SetCurrentRecord(0);
  441. Result:=GetRecord(FBuffers[FBuffercount],gmPrior,True)=grOK;
  442. if result then
  443. begin
  444. If FRecordCount=0 then ActivateBuffers;
  445. shiftbuffersforward;
  446. if FRecordcount<FBuffercount then
  447. inc(FRecordCount);
  448. end
  449. else
  450. cursorposchanged;
  451. {$ifdef dsdebug}
  452. Writeln ('Result getting prior record : ',Result);
  453. {$endif}
  454. end;
  455. Function TDataset.GetPriorRecords: Longint;
  456. begin
  457. Result:=0;
  458. {$ifdef dsdebug}
  459. Writeln ('Getting previous record(s), need :',FBufferCount);
  460. {$endif}
  461. While (FRecordCount<FbufferCount) and GetPriorRecord do
  462. Inc(Result);
  463. end;
  464. Function TDataset.GetRecNo: Longint;
  465. begin
  466. Result := -1;
  467. end;
  468. Function TDataset.GetRecordCount: Longint;
  469. begin
  470. Result := -1;
  471. end;
  472. Procedure TDataset.InitFieldDefs;
  473. begin
  474. //!! To be implemented
  475. end;
  476. Procedure TDataset.InitRecord(Buffer: PChar);
  477. begin
  478. InternalInitRecord(Buffer);
  479. ClearCalcFields(Buffer);
  480. end;
  481. Procedure TDataset.InternalCancel;
  482. begin
  483. //!! To be implemented
  484. end;
  485. Procedure TDataset.InternalEdit;
  486. begin
  487. //!! To be implemented
  488. end;
  489. Procedure TDataset.InternalRefresh;
  490. begin
  491. //!! To be implemented
  492. end;
  493. Procedure TDataset.OpenCursor(InfoQuery: Boolean);
  494. begin
  495. //!! To be implemented
  496. end;
  497. Procedure TDataset.RefreshInternalCalcFields(Buffer: PChar);
  498. begin
  499. //!! To be implemented
  500. end;
  501. Function TDataset.SetTempState(const Value: TDataSetState): TDataSetState;
  502. begin
  503. result := FState;
  504. FState := value;
  505. inc(FDisableControlsCount);
  506. end;
  507. Procedure TDataset.RestoreState(const Value: TDataSetState);
  508. begin
  509. FState := value;
  510. dec(FDisableControlsCount);
  511. end;
  512. function TDataset.GetActive : boolean;
  513. begin
  514. result := FState <> dsInactive;
  515. end;
  516. Procedure TDataset.SetActive (Value : Boolean);
  517. begin
  518. if value and (Fstate = dsInactive) then
  519. begin
  520. if csLoading in ComponentState then
  521. begin
  522. FOpenAfterRead := true;
  523. exit;
  524. end
  525. else
  526. DoInternalOpen;
  527. end
  528. else if not value and (Fstate <> dsinactive) then
  529. DoInternalClose(True);
  530. end;
  531. procedure TDataset.Loaded;
  532. begin
  533. inherited;
  534. if FOpenAfterRead then SetActive(true);
  535. end;
  536. procedure TDataSet.RecalcBufListSize;
  537. var
  538. i, j, ABufferCount: Integer;
  539. DataLink: TDataLink;
  540. begin
  541. {$ifdef dsdebug}
  542. Writeln('Recalculating buffer list size - check cursor');
  543. {$endif}
  544. If Not IsCursorOpen Then
  545. Exit;
  546. {$ifdef dsdebug}
  547. Writeln('Recalculating buffer list size');
  548. {$endif}
  549. ABufferCount := DefaultBufferCount;
  550. for i := 0 to FDataSources.Count - 1 do
  551. for j := 0 to TDataSource(FDataSources[i]).DataLinks.Count - 1 do
  552. begin
  553. DataLink:=TDataLink(TDataSource(FDataSources[i]).DataLinks[j]);
  554. if DataLink.BufferCount>ABufferCount then
  555. ABufferCount:=DataLink.BufferCount;
  556. end;
  557. If (FBufferCount=ABufferCount) Then
  558. exit;
  559. {$ifdef dsdebug}
  560. Writeln('Setting buffer list size');
  561. {$endif}
  562. SetBufListSize(ABufferCount);
  563. {$ifdef dsdebug}
  564. Writeln('Getting next buffers');
  565. {$endif}
  566. GetNextRecords;
  567. {$Ifdef dsDebug}
  568. WriteLn(
  569. 'SetBufferCount: FActiveRecord=',FActiveRecord,
  570. ' FCurrentRecord=',FCurrentRecord,
  571. ' FBufferCount= ',FBufferCount,
  572. ' FRecordCount=',FRecordCount);
  573. {$Endif}
  574. end;
  575. Procedure TDataset.SetBookmarkStr(const Value: TBookmarkStr);
  576. begin
  577. GotoBookMark(Pointer(Value))
  578. end;
  579. Procedure TDataset.SetBufListSize(Value: Longint);
  580. Var I : longint;
  581. begin
  582. {$ifdef dsdebug}
  583. Writeln ('SetBufListSize: ',Value);
  584. {$endif}
  585. If Value=FBufferCount Then
  586. exit;
  587. If Value>FBufferCount then
  588. begin
  589. {$ifdef dsdebug}
  590. Writeln (' Reallocating memory :',(Value+1)*SizeOf(PChar));
  591. {$endif}
  592. ReAllocMem(FBuffers,(Value+1)*SizeOf(PChar));
  593. {$ifdef dsdebug}
  594. Writeln (' Filling memory :',(Value+1-FBufferCount)*SizeOf(PChar));
  595. {$endif}
  596. FillChar(FBuffers[FBufferCount],(Value+1-FBufferCount)*SizeOF(Pchar),#0);
  597. {$ifdef dsdebug}
  598. Writeln (' Filled memory :');
  599. {$endif}
  600. Try
  601. {$ifdef dsdebug}
  602. Writeln (' Assigning buffers :',(Value)*SizeOf(PChar));
  603. {$endif}
  604. For I:=FBufferCount to Value do
  605. FBuffers[i]:=AllocRecordBuffer;
  606. {$ifdef dsdebug}
  607. Writeln (' Assigned buffers ',FBufferCount,' :',(Value)*SizeOf(PChar));
  608. {$endif}
  609. except
  610. I:=FBufferCount;
  611. While (I<(Value+1)) and (FBuffers[i]<>Nil) do
  612. begin
  613. FreeRecordBuffer(FBuffers[i]);
  614. Inc(i);
  615. end;
  616. raise;
  617. end;
  618. end
  619. else
  620. begin
  621. {$ifdef dsdebug}
  622. Writeln (' Freeing buffers :',FBufferCount-Value);
  623. {$endif}
  624. if (value > -1) and (FActiveRecord>Value-1) then
  625. begin
  626. for i := 0 to (FActiveRecord-Value) do
  627. shiftbuffersbackward;
  628. FActiverecord := Value -1;
  629. end;
  630. If Assigned(FBuffers) then
  631. begin
  632. For I:=Value+1 to FBufferCount do
  633. FreeRecordBuffer(FBuffers[i]);
  634. ReAllocMem(FBuffers,(Value+1)*SizeOf(Pchar));
  635. end;
  636. if FRecordcount > Value then FRecordcount := Value;
  637. end;
  638. If Value=-1 then
  639. Value:=0;
  640. FBufferCount:=Value;
  641. {$ifdef dsdebug}
  642. Writeln (' SetBufListSize: Final FBufferCount=',FBufferCount);
  643. {$endif}
  644. end;
  645. Procedure TDataset.SetChildOrder(Component: TComponent; Order: Longint);
  646. begin
  647. //!! To be implemented
  648. end;
  649. Procedure TDataset.SetCurrentRecord(Index: Longint);
  650. begin
  651. If FCurrentRecord<>Index then
  652. begin
  653. {$ifdef DSdebug}
  654. Writeln ('Setting current record to',index);
  655. {$endif}
  656. Case GetBookMarkFlag(FBuffers[Index]) of
  657. bfCurrent : InternalSetToRecord(FBuffers[Index]);
  658. bfBOF : InternalFirst;
  659. bfEOF : InternalLast;
  660. end;
  661. FCurrentRecord:=index;
  662. end;
  663. end;
  664. Procedure TDataset.SetField (Index : Longint;Value : TField);
  665. begin
  666. //!! To be implemented
  667. end;
  668. Procedure TDataset.SetFilterOptions(Value: TFilterOptions);
  669. begin
  670. //!! To be implemented
  671. end;
  672. Procedure TDataset.SetFilterText(const Value: string);
  673. begin
  674. FFilterText := value;
  675. end;
  676. Procedure TDataset.SetFiltered(Value: Boolean);
  677. begin
  678. FFiltered := value;
  679. end;
  680. Procedure TDataset.SetFound(const Value: Boolean);
  681. begin
  682. //!! To be implemented
  683. end;
  684. Procedure TDataset.SetModified(Value: Boolean);
  685. begin
  686. FModified := value;
  687. end;
  688. Procedure TDataset.SetName(const Value: TComponentName);
  689. begin
  690. //!! To be implemented
  691. inherited SetName(Value);
  692. end;
  693. Procedure TDataset.SetOnFilterRecord(const Value: TFilterRecordEvent);
  694. begin
  695. //!! To be implemented
  696. end;
  697. Procedure TDataset.SetRecNo(Value: Longint);
  698. begin
  699. //!! To be implemented
  700. end;
  701. Procedure TDataset.SetState(Value: TDataSetState);
  702. begin
  703. If Value<>FState then
  704. begin
  705. FState:=Value;
  706. DataEvent(deUpdateState,0);
  707. end;
  708. end;
  709. Function TDataset.TempBuffer: PChar;
  710. begin
  711. //!! To be implemented
  712. end;
  713. Procedure TDataset.UpdateIndexDefs;
  714. begin
  715. // Empty Abstract
  716. end;
  717. Function TDataset.ControlsDisabled: Boolean;
  718. begin
  719. Result := (FDisableControlsCount > 0);
  720. end;
  721. Function TDataset.ActiveBuffer: PChar;
  722. begin
  723. {$ifdef dsdebug}
  724. Writeln ('Active buffer requested. Returning:',ActiveRecord);
  725. {$endif}
  726. Result:=FBuffers[FActiveRecord];
  727. end;
  728. Procedure TDataset.Append;
  729. begin
  730. DoInsertAppend(True);
  731. end;
  732. Procedure TDataset.AppendRecord(const Values: array of const);
  733. begin
  734. //!! To be implemented
  735. end;
  736. Function TDataset.BookmarkValid(ABookmark: TBookmark): Boolean;
  737. {
  738. Should be overridden by descendant objects.
  739. }
  740. begin
  741. Result:=False
  742. end;
  743. Procedure TDataset.Cancel;
  744. begin
  745. If State in [dsEdit,dsInsert] then
  746. begin
  747. DataEvent(deCheckBrowseMode,0);
  748. DoBeforeCancel;
  749. UpdateCursorPos;
  750. InternalCancel;
  751. FreeFieldBuffers;
  752. if (state = dsInsert) and (FRecordcount = 1) then
  753. begin
  754. FEOF := true;
  755. FBOF := true;
  756. FRecordcount := 0;
  757. SetState(dsBrowse);
  758. DataEvent(deDatasetChange,0);
  759. end
  760. else
  761. begin
  762. SetState(dsBrowse);
  763. SetCurrentRecord(FActiverecord);
  764. resync([]);
  765. end;
  766. DoAfterCancel;
  767. end;
  768. end;
  769. Procedure TDataset.CheckBrowseMode;
  770. begin
  771. CheckActive;
  772. DataEvent(deCheckBrowseMode,0);
  773. If State In [dsedit,dsinsert] then
  774. begin
  775. UpdateRecord;
  776. If Modified then
  777. Post
  778. else
  779. Cancel;
  780. end;
  781. end;
  782. Procedure TDataset.ClearFields;
  783. begin
  784. //!! To be implemented
  785. end;
  786. Procedure TDataset.Close;
  787. begin
  788. Active:=False;
  789. end;
  790. Function TDataset.CompareBookmarks(Bookmark1, Bookmark2: TBookmark): Longint;
  791. begin
  792. Result:=0;
  793. end;
  794. Function TDataset.CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream;
  795. begin
  796. Result:=Nil;
  797. end;
  798. Procedure TDataset.CursorPosChanged;
  799. begin
  800. FCurrentRecord:=-1;
  801. end;
  802. Procedure TDataset.Delete;
  803. begin
  804. If Not CanModify then
  805. DatabaseError(SDatasetReadOnly,Self);
  806. if State in [dsInsert] then
  807. begin
  808. Cancel;
  809. end else begin
  810. DataEvent(deCheckBrowseMode,0);
  811. {$ifdef dsdebug}
  812. writeln ('Delete: checking required fields');
  813. {$endif}
  814. DoBeforeDelete;
  815. DoBeforeScroll;
  816. If Not TryDoing(@InternalDelete,OnPostError) then exit;
  817. {$ifdef dsdebug}
  818. writeln ('Delete: Internaldelete succeeded');
  819. {$endif}
  820. FreeFieldBuffers;
  821. SetState(dsBrowse);
  822. {$ifdef dsdebug}
  823. writeln ('Delete: Browse mode set');
  824. {$endif}
  825. SetCurrentRecord(FActiverecord);
  826. Resync([]);
  827. DoAfterDelete;
  828. DoAfterScroll;
  829. end;
  830. end;
  831. Procedure TDataset.DisableControls;
  832. begin
  833. If FDisableControlsCount=0 then
  834. begin
  835. { Save current state,
  836. needed to detect change of state when enabling controls.
  837. }
  838. FDisableControlsState:=FState;
  839. FEnableControlsEvent:=deDatasetChange;
  840. end;
  841. Inc(FDisableControlsCount);
  842. end;
  843. Procedure TDataset.DoInsertAppend(DoAppend : Boolean);
  844. procedure DoInsert;
  845. Var BookBeforeInsert : TBookmarkStr;
  846. TempBuf : pointer;
  847. begin
  848. // need to scroll up al buffers after current one,
  849. // but copy current bookmark to insert buffer.
  850. If FRecordcount > 0 then BookBeforeInsert:=Bookmark;
  851. if FActiveRecord < FRecordCount-1 then
  852. begin
  853. TempBuf := FBuffers[FBuffercount];
  854. move(FBuffers[FActiveRecord],FBuffers[FActiveRecord+1],(Fbuffercount-FActiveRecord)*sizeof(FBuffers[0]));
  855. FBuffers[FActiveRecord]:=TempBuf;
  856. end
  857. else
  858. inc(FActiveRecord);
  859. // Active buffer is now edit buffer. Initialize.
  860. InitRecord(FBuffers[FActiveRecord]);
  861. cursorposchanged;
  862. // Put bookmark in edit buffer.
  863. if FRecordCount=0 then
  864. begin
  865. fEOF := false;
  866. SetBookmarkFlag(ActiveBuffer,bfBOF)
  867. end
  868. else
  869. begin
  870. fBOF := false;
  871. if FRecordcount > 0 then SetBookMarkData(ActiveBuffer,pointer(BookBeforeInsert));
  872. end;
  873. // update buffer count.
  874. If FRecordCount<FBufferCount then
  875. Inc(FRecordCount);
  876. end;
  877. begin
  878. If Not CanModify then
  879. DatabaseError(SDatasetReadOnly,Self);
  880. CheckBrowseMode;
  881. DoBeforeInsert;
  882. DoBeforeScroll;
  883. If Not DoAppend then
  884. begin
  885. {$ifdef dsdebug}
  886. Writeln ('going to insert mode');
  887. {$endif}
  888. DoInsert;
  889. end
  890. else
  891. begin
  892. {$ifdef dsdebug}
  893. Writeln ('going to append mode');
  894. {$endif}
  895. ClearBuffers;
  896. InternalLast;
  897. GetPriorRecords;
  898. FActiveRecord:=FRecordCount-1;
  899. DoInsert;
  900. SetBookmarkFlag(ActiveBuffer,bfEOF);
  901. FEOF := true;
  902. end;
  903. SetState(dsInsert);
  904. try
  905. DoOnNewRecord;
  906. except
  907. SetCurrentRecord(FActiverecord);
  908. resync([]);
  909. raise;
  910. end;
  911. // mark as not modified.
  912. FModified:=False;
  913. // Final events.
  914. DataEvent(deDatasetChange,0);
  915. DoAfterInsert;
  916. DoAfterScroll;
  917. {$ifdef dsdebug}
  918. Writeln ('Done with append');
  919. {$endif}
  920. end;
  921. Procedure TDataset.Edit;
  922. begin
  923. If Not CanModify then
  924. DatabaseError(SDatasetReadOnly,Self);
  925. If State in [dsedit,dsinsert] then exit;
  926. If FRecordCount = 0 then
  927. begin
  928. Append;
  929. Exit;
  930. end;
  931. CheckBrowseMode;
  932. DoBeforeEdit;
  933. If Not TryDoing(@InternalEdit,OnEditError) then
  934. exit;
  935. SetState(dsedit);
  936. DataEvent(deRecordChange,0);
  937. DoAfterEdit;
  938. end;
  939. Procedure TDataset.EnableControls;
  940. begin
  941. If FDisableControlsCount>0 then
  942. begin
  943. Dec(FDisableControlsCount);
  944. If FDisableControlsCount=0 then
  945. begin
  946. // State changed since disablecontrols ?
  947. If FDisableControlsState<>FState then
  948. DataEvent(deUpdateState,0);
  949. If (FDisableControlsState<>dsInactive) and (FState<>dsInactive) then
  950. DataEvent(FEnableControlsEvent,0);
  951. end;
  952. end;
  953. end;
  954. Function TDataset.FieldByName(const FieldName: string): TField;
  955. begin
  956. Result:=FindField(FieldName);
  957. If Result=Nil then
  958. DatabaseErrorFmt(SFieldNotFound,[FieldName],Self);
  959. end;
  960. Function TDataset.FindField(const FieldName: string): TField;
  961. begin
  962. Result:=FFieldList.FindField(FieldName);
  963. end;
  964. Function TDataset.FindFirst: Boolean;
  965. begin
  966. //!! To be implemented
  967. end;
  968. Function TDataset.FindLast: Boolean;
  969. begin
  970. //!! To be implemented
  971. end;
  972. Function TDataset.FindNext: Boolean;
  973. begin
  974. //!! To be implemented
  975. end;
  976. Function TDataset.FindPrior: Boolean;
  977. begin
  978. //!! To be implemented
  979. end;
  980. Procedure TDataset.First;
  981. begin
  982. CheckBrowseMode;
  983. DoBeforeScroll;
  984. ClearBuffers;
  985. try
  986. InternalFirst;
  987. GetNextRecords;
  988. finally
  989. FBOF:=True;
  990. DataEvent(deDatasetChange,0);
  991. DoAfterScroll;
  992. end;
  993. end;
  994. Procedure TDataset.FreeBookmark(ABookmark: TBookmark);
  995. begin
  996. FreeMem(ABookMark,FBookMarkSize);
  997. end;
  998. Function TDataset.GetBookmark: TBookmark;
  999. begin
  1000. if BookmarkAvailable then
  1001. begin
  1002. GetMem (Result,FBookMarkSize);
  1003. GetBookMarkdata(ActiveBuffer,Result);
  1004. end
  1005. else
  1006. Result:=Nil;
  1007. end;
  1008. Function TDataset.GetCurrentRecord(Buffer: PChar): Boolean;
  1009. begin
  1010. Result:=False;
  1011. end;
  1012. Procedure TDataset.GetFieldList(List: TList; const FieldNames: string);
  1013. Function NextName(Var S : String) : String;
  1014. Var
  1015. P : integer;
  1016. begin
  1017. P:=Pos(';',S);
  1018. If (P=0) then
  1019. P:=Length(S)+1;
  1020. Result:=Copy(S,1,P-1);
  1021. system.Delete(S,1,P);
  1022. end;
  1023. var
  1024. F: TField;
  1025. Names,N : String;
  1026. begin
  1027. Names:=FieldNames;
  1028. N:=Nextname(Names);
  1029. while (N<>'') do
  1030. begin
  1031. F:=FieldByName(N);
  1032. If Assigned(List) then
  1033. List.Add(F);
  1034. N:=NextName(Names);
  1035. end;
  1036. end;
  1037. Procedure TDataset.GetFieldNames(List: TStrings);
  1038. begin
  1039. FFieldList.GetFieldNames(List);
  1040. end;
  1041. Procedure TDataset.GotoBookmark(ABookmark: TBookmark);
  1042. begin
  1043. If Assigned(ABookMark) then
  1044. begin
  1045. CheckBrowseMode;
  1046. DoBeforeScroll;
  1047. InternalGotoBookMark(ABookMark);
  1048. Resync([rmExact,rmCenter]);
  1049. DoAfterScroll;
  1050. end;
  1051. end;
  1052. Procedure TDataset.Insert;
  1053. begin
  1054. DoInsertAppend(False);
  1055. end;
  1056. Procedure TDataset.InsertRecord(const Values: array of const);
  1057. begin
  1058. //!! To be implemented
  1059. end;
  1060. Function TDataset.IsEmpty: Boolean;
  1061. begin
  1062. Result:=(Bof and Eof);
  1063. end;
  1064. Function TDataset.IsSequenced: Boolean;
  1065. begin
  1066. Result := True;
  1067. end;
  1068. Procedure TDataset.Last;
  1069. begin
  1070. CheckBrowseMode;
  1071. DoBeforeScroll;
  1072. ClearBuffers;
  1073. try
  1074. InternalLast;
  1075. GetPriorRecords;
  1076. FActiveRecord:=FRecordCount-1;
  1077. finally
  1078. FEOF:=true;
  1079. DataEvent(deDataSetChange, 0);
  1080. DoAfterScroll;
  1081. end;
  1082. end;
  1083. Function TDataset.MoveBy(Distance: Longint): Longint;
  1084. Var
  1085. TheResult: Integer;
  1086. Function Scrollforward : Integer;
  1087. begin
  1088. Result:=0;
  1089. {$ifdef dsdebug}
  1090. Writeln('Scrolling forward :',Distance);
  1091. Writeln('Active buffer : ',FActiveRecord);
  1092. Writeln('RecordCount : ',FRecordCount);
  1093. WriteLn('BufferCount : ',FBufferCount);
  1094. {$endif}
  1095. FBOF:=False;
  1096. While (Distance>0) and not FEOF do
  1097. begin
  1098. If FActiveRecord<FRecordCount-1 then
  1099. begin
  1100. Inc(FActiveRecord);
  1101. Dec(Distance);
  1102. Inc(TheResult); //Inc(Result);
  1103. end
  1104. else
  1105. begin
  1106. {$ifdef dsdebug}
  1107. Writeln('Moveby : need next record');
  1108. {$endif}
  1109. If GetNextRecord then
  1110. begin
  1111. Dec(Distance);
  1112. Dec(Result);
  1113. Inc(TheResult); //Inc(Result);
  1114. end
  1115. else
  1116. FEOF:=true;
  1117. end;
  1118. end
  1119. end;
  1120. Function ScrollBackward : Integer;
  1121. begin
  1122. if FIsUniDirectional then DatabaseError(SUniDirectional);
  1123. Result:=0;
  1124. {$ifdef dsdebug}
  1125. Writeln('Scrolling backward:',Abs(Distance));
  1126. Writeln('Active buffer : ',FActiveRecord);
  1127. Writeln('RecordCunt : ',FRecordCount);
  1128. WriteLn('BufferCount : ',FBufferCount);
  1129. {$endif}
  1130. FEOF:=False;
  1131. While (Distance<0) and not FBOF do
  1132. begin
  1133. If FActiveRecord>0 then
  1134. begin
  1135. Dec(FActiveRecord);
  1136. Inc(Distance);
  1137. Dec(TheResult); //Dec(Result);
  1138. end
  1139. else
  1140. begin
  1141. {$ifdef dsdebug}
  1142. Writeln('Moveby : need next record');
  1143. {$endif}
  1144. If GetPriorRecord then
  1145. begin
  1146. Inc(Distance);
  1147. Inc(Result);
  1148. Dec(TheResult); //Dec(Result);
  1149. end
  1150. else
  1151. FBOF:=true;
  1152. end;
  1153. end
  1154. end;
  1155. Var
  1156. PrevRecordCount : Integer;
  1157. Scrolled : Integer;
  1158. begin
  1159. CheckBrowseMode;
  1160. Result:=0; TheResult:=0;
  1161. PrevRecordCount:=FRecordCount;
  1162. If ((Distance>0) and FEOF) or
  1163. ((Distance<0) and FBOF) then
  1164. exit;
  1165. DoBeforeScroll;
  1166. Try
  1167. If Distance>0 then
  1168. Scrolled:=ScrollForward
  1169. else
  1170. Scrolled:=ScrollBackward;
  1171. finally
  1172. {$ifdef dsdebug}
  1173. WriteLn('ActiveRecord=', FActiveRecord,' FEOF=',FEOF,' FBOF=',FBOF);
  1174. {$Endif}
  1175. If FRecordCount<>PrevRecordCount then
  1176. DataEvent(deDatasetChange,0)
  1177. else
  1178. DataEvent(deDatasetScroll,Scrolled);
  1179. DoAfterScroll;
  1180. Result:=TheResult;
  1181. end;
  1182. end;
  1183. Procedure TDataset.Next;
  1184. begin
  1185. MoveBy(1);
  1186. end;
  1187. Procedure TDataset.Open;
  1188. begin
  1189. Active:=True;
  1190. end;
  1191. Procedure TDataset.Post;
  1192. Procedure Checkrequired;
  1193. Var I : longint;
  1194. begin
  1195. For I:=0 to FFieldList.Count-1 do
  1196. With FFieldList[i] do
  1197. // Required fields that are NOT autoinc !! Autoinc cannot be set !!
  1198. if Required and not ReadOnly and
  1199. (FieldKind=fkData) and Not (DataType=ftAutoInc) then
  1200. DatabaseErrorFmt(SNeedField,[DisplayName],Self);
  1201. end;
  1202. begin
  1203. if State in [dsEdit,dsInsert] then
  1204. begin
  1205. DataEvent(deUpdateRecord,0);
  1206. DataEvent(deCheckBrowseMode,0);
  1207. {$ifdef dsdebug}
  1208. writeln ('Post: checking required fields');
  1209. {$endif}
  1210. CheckRequired;
  1211. DoBeforePost;
  1212. If Not TryDoing(@InternalPost,OnPostError) then exit;
  1213. cursorposchanged;
  1214. {$ifdef dsdebug}
  1215. writeln ('Post: Internalpost succeeded');
  1216. {$endif}
  1217. FreeFieldBuffers;
  1218. // SetCurrentRecord(FActiverecord);
  1219. Resync([]);
  1220. SetState(dsBrowse);
  1221. {$ifdef dsdebug}
  1222. writeln ('Post: Browse mode set');
  1223. {$endif}
  1224. DoAfterPost;
  1225. end;
  1226. end;
  1227. Procedure TDataset.Prior;
  1228. begin
  1229. MoveBy(-1);
  1230. end;
  1231. Procedure TDataset.Refresh;
  1232. begin
  1233. CheckbrowseMode;
  1234. UpdateCursorPos;
  1235. InternalRefresh;
  1236. SetCurrentRecord(FActiverecord);
  1237. Resync([]);
  1238. end;
  1239. Procedure TDataset.RegisterDataSource(ADatasource : TDataSource);
  1240. begin
  1241. FDatasources.Add(ADataSource);
  1242. RecalcBufListSize;
  1243. end;
  1244. Procedure TDataset.Resync(Mode: TResyncMode);
  1245. var i,count : integer;
  1246. begin
  1247. // See if we can find the requested record.
  1248. {$ifdef dsdebug}
  1249. Writeln ('Resync called');
  1250. {$endif}
  1251. // place the cursor of the underlying dataset to the active record
  1252. // SetCurrentRecord(FActiverecord);
  1253. // Now look if the data on the current cursor of the underlying dataset is still available
  1254. If GetRecord(Fbuffers[0],gmcurrent,False)<>grOk Then
  1255. // If that fails and rmExact is set, then raise an exception
  1256. If rmExact in Mode then
  1257. DatabaseError(SNoSuchRecord,Self)
  1258. // else, if rmexact is not set, try to fetch the next or prior record in the underlying dataset
  1259. else if (GetRecord(Fbuffers[0],gmnext,True)<>grOk) and
  1260. (GetRecord(Fbuffers[0],gmprior,True)<>grOk) then
  1261. begin
  1262. {$ifdef dsdebug}
  1263. Writeln ('Resync: fuzzy resync');
  1264. {$endif}
  1265. // nothing found, invalidate buffer and bail out.
  1266. ClearBuffers;
  1267. DataEvent(deDatasetChange,0);
  1268. exit;
  1269. end;
  1270. FCurrentRecord := 0;
  1271. FEOF := false;
  1272. FBOF := false;
  1273. // If we've arrived here, FBuffer[0] is the current record
  1274. If (rmCenter in Mode) then
  1275. count := (FRecordCount div 2)
  1276. else
  1277. count := FActiveRecord;
  1278. i := 0;
  1279. FRecordcount := 1;
  1280. FActiveRecord := 0;
  1281. // Fill the buffers before the active record
  1282. while (i < count) and GetPriorRecord do
  1283. inc(i);
  1284. FActiveRecord := i;
  1285. // Fill the rest of the buffer
  1286. getnextrecords;
  1287. // If the buffer is not full yet, try to fetch some more prior records
  1288. if FRecordcount < FBuffercount then inc(FActiverecord,getpriorrecords);
  1289. // That's all folks!
  1290. DataEvent(deDatasetChange,0);
  1291. end;
  1292. Procedure TDataset.SetFields(const Values: array of const);
  1293. Var I : longint;
  1294. begin
  1295. For I:=0 to high(Values) do
  1296. Case Values[I].vtype of
  1297. vtInteger : FieldByNumber(i).AsLongInt:=Values[I].VInteger;
  1298. // needs Completion..
  1299. end;
  1300. end;
  1301. Function TDataset.Translate(Src, Dest: PChar; ToOem: Boolean): Integer;
  1302. begin
  1303. //!! To be implemented
  1304. end;
  1305. Function Tdataset.TryDoing (P : TDataOperation; Ev : TDatasetErrorEvent) : Boolean;
  1306. Var Retry : TDataAction;
  1307. begin
  1308. {$ifdef dsdebug}
  1309. Writeln ('Trying to do');
  1310. If P=Nil then writeln ('Procedure to call is nil !!!');
  1311. {$endif dsdebug}
  1312. Result:=True;
  1313. Retry:=daRetry;
  1314. while Retry=daRetry do
  1315. Try
  1316. {$ifdef dsdebug}
  1317. Writeln ('Trying : updatecursorpos');
  1318. {$endif dsdebug}
  1319. UpdateCursorPos;
  1320. {$ifdef dsdebug}
  1321. Writeln ('Trying to do it');
  1322. {$endif dsdebug}
  1323. P;
  1324. exit;
  1325. except
  1326. On E : EDatabaseError do
  1327. begin
  1328. retry:=daFail;
  1329. If Assigned(Ev) then
  1330. Ev(Self,E,Retry);
  1331. Case Retry of
  1332. daFail : Raise;
  1333. daAbort : Result:=False;
  1334. end;
  1335. end;
  1336. else
  1337. Raise;
  1338. end;
  1339. {$ifdef dsdebug}
  1340. Writeln ('Exit Trying to do');
  1341. {$endif dsdebug}
  1342. end;
  1343. Procedure TDataset.UpdateCursorPos;
  1344. begin
  1345. If FRecordCount>0 then
  1346. SetCurrentRecord(FactiveRecord);
  1347. end;
  1348. Procedure TDataset.UpdateRecord;
  1349. begin
  1350. if not (State in dsEditModes) then
  1351. DatabaseError(SNotInEditState, Self);
  1352. DataEvent(deUpdateRecord, 0);
  1353. end;
  1354. Procedure TDataset.RemoveField (Field : TField);
  1355. begin
  1356. //!! To be implemented
  1357. end;
  1358. Function TDataset.Getfieldcount : Longint;
  1359. begin
  1360. Result:=FFieldList.Count;
  1361. end;
  1362. Procedure TDataset.ShiftBuffersBackward;
  1363. var TempBuf : pointer;
  1364. begin
  1365. TempBuf := FBuffers[0];
  1366. move(FBuffers[1],FBuffers[0],(fbuffercount)*sizeof(FBuffers[0]));
  1367. FBuffers[buffercount]:=TempBuf;
  1368. end;
  1369. Procedure TDataset.ShiftBuffersForward;
  1370. var TempBuf : pointer;
  1371. begin
  1372. TempBuf := FBuffers[FBufferCount];
  1373. move(FBuffers[0],FBuffers[1],(fbuffercount)*sizeof(FBuffers[0]));
  1374. FBuffers[0]:=TempBuf;
  1375. end;
  1376. function TDataset.GetFieldValues(Fieldname : string) : string;
  1377. begin
  1378. result := findfield(Fieldname).asstring;
  1379. end;
  1380. procedure TDataset.SetFieldValues(Fieldname : string;value : string);
  1381. begin
  1382. findfield(Fieldname).asstring := value;
  1383. end;
  1384. Procedure TDataset.UnRegisterDataSource(ADatasource : TDatasource);
  1385. begin
  1386. FDataSources.Remove(ADataSource);
  1387. end;
  1388. {
  1389. $Log$
  1390. Revision 1.30 2005-01-12 10:27:57 michael
  1391. * Patch from Joost Van der Sluis:
  1392. - implemented ControlsDisabled
  1393. Revision 1.29 2004/12/13 19:18:51 michael
  1394. * Patch from Joost van der Sluis
  1395. - TDataset.IsSequenced returns True, like Delphi does
  1396. - TDataset.RecNo returns -1, just like Delphi
  1397. - TDataset.GetRecordCount returns -1, just like Delphi
  1398. Revision 1.28 2004/11/05 08:32:02 michael
  1399. TBufDataset.inc:
  1400. - replaced Freemem by Reallocmem, Free by FreeAndNil
  1401. Database.inc:
  1402. - Moved Active property from TSQLTransaction to TDBTransaction
  1403. - Gives an error if the database of an active transaction is changed
  1404. Dataset.inc
  1405. - Don't distribute events if FDisableControlsCount > 0
  1406. - Replaced FActive by FState<>dsInactive
  1407. - Set EOF after append
  1408. db.pp:
  1409. - Removed duplicate definition of TAlignment
  1410. - Moved Active property from TSQLTransaction to TDBTransaction
  1411. - Replaced FActive by FState<>dsInactive
  1412. - Gives an error if the database of an active transaction is changed
  1413. sqldb:
  1414. - Moved Active property from TSQLTransaction to TDBTransaction
  1415. - replaced Freemem by Reallocmem, Free by FreeAndNil
  1416. IBConnection:
  1417. - Moved FSQLDAAllocated to the cursor
  1418. PQConnection:
  1419. - Don't try to free the statement if a fatal error occured
  1420. Revision 1.27 2004/10/27 07:23:13 michael
  1421. + Patch from Joost Van der Sluis to fix transactions
  1422. Revision 1.26 2004/10/16 09:27:23 michael
  1423. + Fixed GotoBookMark (as suggested by Americo Luiz)
  1424. Revision 1.25 2004/10/10 14:25:21 michael
  1425. + Small fix for close so it does not check browsemode
  1426. Revision 1.24 2004/09/26 16:55:24 michael
  1427. * big patch from Joost van der Sluis
  1428. bufdataset.inc:
  1429. fix getrecord (prior)
  1430. getcanmodify default false
  1431. database.inc / db.inc:
  1432. Added transactions
  1433. dataset.inc:
  1434. raise error if trying to insert into an readonly dataset
  1435. db.inc:
  1436. remove published properties from bufdataset
  1437. changed ancestor of tbufdataset to tdbdataset
  1438. Revision 1.23 2004/09/15 12:22:33 michael
  1439. Suggested fix from Luiz Americo to .resync method
  1440. Revision 1.22 2004/08/30 12:02:17 michael
  1441. + Patch from Joost van der Sluis for Insert/Resync
  1442. Revision 1.21 2004/08/23 07:30:19 michael
  1443. + Fixes from joost van der sluis: tfieldsdefs.tdatafield and size, cancel of only record and dataset.fieldvalyes
  1444. Revision 1.20 2004/08/21 21:10:00 michael
  1445. * Patch from Joost van der Sluis
  1446. - Empty recordsets don't show any bogus data anymore
  1447. - Floatfiels.gettext fix
  1448. - SetBufListsize fix forTDBGrid
  1449. Revision 1.19 2004/08/14 12:46:36 michael
  1450. + Patch from Joost van der Sluis to implement Modified and UpdateRecord event
  1451. Revision 1.18 2004/08/13 07:06:02 michael
  1452. + Rework of buffer management by Joost Van der Sluis
  1453. Revision 1.17 2004/08/03 19:08:48 michael
  1454. + Latest patch from Micha Nelissen
  1455. Revision 1.16 2004/08/02 15:13:42 michael
  1456. + Patch from Micha Nelissen to implement Delete method
  1457. Revision 1.15 2004/07/25 11:32:40 michael
  1458. * Patches from Joost van der Sluis
  1459. interbase.pp:
  1460. * Removed unused Fprepared
  1461. * Changed the error message 'database connect string not filled
  1462. in' to 'database connect string (databasename) not filled in'
  1463. * Preparestatement and execute now checks if transaction is
  1464. assigned (in stead of crashing if it isn't) and if the
  1465. transaction isn't started, it calls starttransaction.
  1466. dataset.inc:
  1467. * In DoInternalOpen the buffers are now initialised before the
  1468. dataset is set into browse-state
  1469. database.inc and db.pp:
  1470. * If the dataset is created from a stream, the database is opened
  1471. after the dataset is read completely
  1472. Revision 1.13 2004/05/02 21:23:18 peter
  1473. * use ptrint
  1474. Revision 1.12 2004/03/25 20:43:39 michael
  1475. Some compatibility additions
  1476. Revision 1.11 2004/01/05 21:21:38 michael
  1477. + Fix in setbuflistsize for when Value=-1
  1478. Revision 1.10 2003/11/09 21:23:10 michael
  1479. + Patch from Micha Nelissen, fixing some Delphi compatibility issues
  1480. Revision 1.9 2003/10/06 17:04:28 florian
  1481. * small step towards calculated fields
  1482. Revision 1.8 2003/05/06 12:08:52 michael
  1483. + fixed dataset opening buffer issues
  1484. Revision 1.7 2003/02/20 19:25:19 michael
  1485. + Fixes from Jesus Reyes
  1486. Revision 1.6 2002/09/07 15:15:22 peter
  1487. * old logs removed and tabs fixed
  1488. }