forked from Sovos-Compliance/convey-public-libs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kbmMemBinaryStreamFormat.pas
804 lines (698 loc) · 28 KB
/
kbmMemBinaryStreamFormat.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
unit kbmMemBinaryStreamFormat;
interface
{$include kbmMemTable.inc}
// =========================================================================
// Binary stream format for kbmMemTable v. 3.xx+
//
// Copyright 1999-2002 Kim Bo Madsen/Optical Services - Scandinavia
// All rights reserved.
//
// LICENSE AGREEMENT
// PLEASE NOTE THAT THE LICENSE AGREEMENT HAS CHANGED!!! 16. Feb. 2000
//
// You are allowed to use this component in any project for free.
// You are NOT allowed to claim that you have created this component or to
// copy its code into your own component and claim that it was your idea.
//
// -----------------------------------------------------------------------------------
// IM OFFERING THIS FOR FREE FOR YOUR CONVINIENCE, BUT
// YOU ARE REQUIRED TO SEND AN E-MAIL ABOUT WHAT PROJECT THIS COMPONENT (OR DERIVED VERSIONS)
// IS USED FOR !
// -----------------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------------
// PLEASE NOTE THE FOLLOWING ADDITION TO THE LICENSE AGREEMENT:
// If you choose to use this component for generating middleware libraries (with similar
// functionality as dbOvernet, Midas, Asta etc.), those libraries MUST be released as
// Open Source and Freeware!
// -----------------------------------------------------------------------------------
//
// You dont need to state my name in your software, although it would be
// appreciated if you do.
//
// If you find bugs or alter the component (f.ex. see suggested enhancements
// further down), please DONT just send the corrected/new code out on the internet,
// but instead send it to me, so I can put it into the official version. You will
// be acredited if you do so.
//
//
// DISCLAIMER
// By using this component or parts theirof you are accepting the full
// responsibility of the use. You are understanding that the author cant be
// made responsible in any way for any problems occuring using this component.
// You also recognize the author as the creator of this component and agrees
// not to claim otherwize!
//
// Please forward corrected versions (source code ONLY!), comments,
// and emails saying you are using it for this or that project to:
//
// Latest version can be found at:
// http://www.onelist.com/community/memtable
//=============================================================================
// Remove the remark on the next lines if to keep binary file compatibility
// between different versions of TkbmMemTable.
//{$define BINARY_FILE_230_COMPATIBILITY}
//{$define BINARY_FILE_200_COMPATIBILITY}
//{$define BINARY_FILE_1XX_COMPATIBILITY}
//=============================================================================
// History.
// Per v. 3.00, the stream formats will each have their own history.
//
// 3.00a alpha
// Initial v. 3.00 binary stream format release based on the sources of v. 2.53b.
//
// 3.00b beta
// Fixed Floating point error in calculation of progress.
// Bug reported by Fred Schetterer ([email protected])
//
// 3.00c beta
// Fixed bug not setting record flag to record being part of table.
// This would result in massive memory leaks.
//
// 3.00 Final
// Added BufferSize property (default 16384) which controls the internal
// read and write buffer size. Suggested by Ken Schafer ([email protected])
uses
kbmMemTable,Classes,DB,
{$include kbmMemRes.inc}
SysUtils;
type
TkbmStreamFlagUsingIndex = (sfSaveUsingIndex);
TkbmStreamFlagUsingIndexs = set of TkbmStreamFlagUsingIndex;
TkbmCustomBinaryStreamFormat = class(TkbmCustomStreamFormat)
private
Writer:TWriter;
Reader:TReader;
FUsingIndex:TkbmStreamFlagUsingIndexs;
FBuffSize:LongInt;
FileVersion:integer;
InitIndexDef:boolean;
ProgressCnt:integer;
StreamSize:longint;
procedure SetBuffSize(ABuffSize:LongInt);
protected
function GetVersion:string; override;
procedure BeforeSave(ADataset:TkbmCustomMemTable); override;
procedure SaveDef(ADataset:TkbmCustomMemTable); override;
procedure SaveData(ADataset:TkbmCustomMemTable); override;
procedure AfterSave(ADataset:TkbmCustomMemTable); override;
procedure BeforeLoad(ADataset:TkbmCustomMemTable); override;
procedure LoadDef(ADataset:TkbmCustomMemTable); override;
procedure LoadData(ADataset:TkbmCustomMemTable); override;
procedure AfterLoad(ADataset:TkbmCustomMemTable); override;
property sfUsingIndex:TkbmStreamFlagUsingIndexs read FUsingIndex write FUsingIndex;
property BufferSize:LongInt read FBuffSize write SetBuffSize;
public
constructor Create(AOwner:TComponent); override;
end;
TkbmBinaryStreamFormat = class(TkbmCustomBinaryStreamFormat)
published
property Version;
property sfUsingIndex;
property sfData;
property sfCalculated;
property sfLookup;
property sfNonVisible;
property sfBlobs;
property sfDef;
property sfIndexDef;
property sfFiltered;
property sfIgnoreRange;
property sfIgnoreMasterDetail;
property sfDeltas;
property sfDontFilterDeltas;
property sfAppend;
property sfFieldKind;
property sfFromStart;
property OnBeforeLoad;
property OnAfterLoad;
property OnBeforeSave;
property OnAfterSave;
property OnCompress;
property OnDeCompress;
property BufferSize;
end;
{$ifdef LEVEL3}
procedure Register;
{$endif}
implementation
const
// Binary file magic word.
kbmBinaryMagic = '@@BINARY@@';
// Current file versions. V. 1.xx file versions are considered 100, 2.xx are considered 2xx etc.
kbmBinaryFileVersion = 251;
kbmDeltaVersion = 200;
type
TkbmProtCustomMemTable = class(TkbmCustomMemTable);
TkbmProtCommon = class(TkbmCommon);
function TkbmCustomBinaryStreamFormat.GetVersion:string;
begin
Result:='3.00';
end;
constructor TkbmCustomBinaryStreamFormat.Create(AOwner:TComponent);
begin
inherited;
FUsingIndex:=[sfSaveUsingIndex];
FBuffSize:=16384;
end;
procedure TkbmCustomBinaryStreamFormat.SetBuffSize(ABuffSize:LongInt);
begin
if ABuffSize<16384 then ABuffSize:=16384;
FBuffSize:=ABuffSize;
end;
procedure TkbmCustomBinaryStreamFormat.BeforeSave(ADataset:TkbmCustomMemTable);
begin
inherited;
Writer:=TWriter.Create(WorkStream,FBuffSize);
Writer.WriteSignature;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
Writer.WriteInteger(kbmBinaryFileVersion);
{$ENDIF}
end;
procedure TkbmCustomBinaryStreamFormat.AfterSave(ADataset:TkbmCustomMemTable);
begin
Writer.FlushBuffer;
Writer.Free;
Writer:=nil;
TkbmProtCustomMemTable(ADataset).FOverrideActiveRecordBuffer:=nil;
inherited;
end;
procedure TkbmCustomBinaryStreamFormat.SaveDef(ADataset:TkbmCustomMemTable);
var
i:integer;
nf:integer;
begin
// Write field definitions
with TkbmProtCustomMemTable(ADataset) do
begin
// Write fielddefinitions.
nf:=FieldCount;
Writer.WriteListBegin;
if (sfSaveDef in sfDef) then
begin
for i:=0 to nf-1 do
begin
if SaveFields[i]>=0 then
begin
Writer.WriteString(Fields[i].FieldName);
Writer.WriteString(FieldTypeNames[Fields[i].DataType]);
Writer.WriteInteger(Fields[i].Size);
Writer.WriteString(Fields[i].DisplayName);
Writer.WriteString(Fields[i].EditMask);
Writer.WriteInteger(Fields[i].DisplayWidth);
Writer.WriteBoolean(Fields[i].Required);
Writer.WriteBoolean(Fields[i].ReadOnly);
// New for 2.50i BinaryFileVersion 250
if sfSaveFieldKind in sfFieldKind then
Writer.WriteString(FieldKindNames[ord(Fields[i].FieldKind)])
else
Writer.WriteString(FieldKindNames[0]); //fkData.
// New for 2.50o2 BinaryFileVersion 251
{$IFDEF LEVEL4}
Writer.WriteString(Fields[i].DefaultExpression);
{$ELSE}
Writer.WriteString('');
{$ENDIF}
end;
end;
end;
Writer.WriteListEnd;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
// Save index definitions.
Writer.WriteListBegin;
if sfSaveIndexDef in sfIndexDef then
begin
for i:=0 to FIndexDefs.Count-1 do
with FIndexDefs.Items[i] do
begin
Writer.WriteString(Name);
Writer.WriteString(Fields);
{$IFNDEF LEVEL3}
Writer.WriteString(DisplayName);
{$ELSE}
Writer.WriteString(Name);
{$ENDIF}
Writer.WriteBoolean(ixDescending in Options);
Writer.WriteBoolean(ixCaseInSensitive in Options);
{$IFNDEF LEVEL3}
Writer.WriteBoolean(ixNonMaintained in Options);
{$ELSE}
Writer.WriteBoolean(false);
{$ENDIF}
Writer.WriteBoolean(ixUnique in Options);
end;
end;
Writer.WriteListEnd;
{$ENDIF}
end;
end;
procedure TkbmCustomBinaryStreamFormat.SaveData(ADataset:TkbmCustomMemTable);
var
i,j,cnt:integer;
nf:integer;
Accept:boolean;
NewestVersion:boolean;
pRec:PkbmRecord;
UsingIndex:boolean;
begin
with TkbmProtCustomMemTable(ADataset) do
begin
// Write fielddefinitions.
nf:=FieldCount;
// Write all records
FSaveCount:=0;
FSavedCompletely:=true;
Writer.WriteListBegin;
// Check if to write according to current index or not.
UsingIndex:=sfSaveUsingIndex in FUsingIndex;
if UsingIndex then
cnt:=FCurIndex.References.Count
else
cnt:=TkbmProtCommon(Common).FRecords.Count;
for j:=0 to cnt-1 do
begin
// Check if to save more.
if (FSaveLimit>0) and (FSaveCount>=FSaveLimit) then
begin
FSavedCompletely:=false;
break;
end;
// Check if to invoke progress event if any.
if (j mod 100)=0 then Progress(trunc((j/cnt)*100),mtpcSave);
// Setup which record to look at.
if UsingIndex then
FOverrideActiveRecordBuffer:=PkbmRecord(FCurIndex.References.Items[j])
else
FOverrideActiveRecordBuffer:=PkbmRecord(TkbmProtCommon(Common).FRecords.Items[j]);
if (FOverrideActiveRecordBuffer=nil) then continue;
// Calculate fields.
{$IFDEF LEVEL18}
ClearCalcFields(NativeInt(FOverrideActiveRecordBuffer));
GetCalcFields(NativeInt(FOverrideActiveRecordBuffer));
{$ELSE}
ClearCalcFields(TRecordBuffer(FOverrideActiveRecordBuffer));
GetCalcFields(TRecordBuffer(FOverrideActiveRecordBuffer));
{$ENDIF}
// Check filter of record.
Accept:=FilterRecord(FOverrideActiveRecordBuffer,false);
if not Accept then continue;
// Check accept of saving this record.
Accept:=true;
if Assigned(OnSaveRecord) then OnSaveRecord(ADataset,Accept);
if not Accept then continue;
// Write current record.
NewestVersion:=true;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
{$IFNDEF BINARY_FILE_200_COMPATIBILITY}
// New for v. 2.24.
if (not (sfSaveData in sfData)) and (FOverrideActiveRecordBuffer^.UpdateStatus=usUnmodified) then continue;
// New for v. 2.30b
if (not (sfSaveDontFilterDeltas in sfDontFilterDeltas)) and (FOverrideActiveRecordBuffer^.UpdateStatus=usDeleted) then
begin
// Make sure record has not been inserted and deleted again.
pRec:=FOverrideActiveRecordBuffer^.PrevRecordVersion;
while pRec^.PrevRecordVersion<>nil do pRec:=pRec^.PrevRecordVersion;
if pRec^.UpdateStatus=usInserted then continue;
end;
// Write record versions in a list starting with Updatestatus.
Writer.WriteListBegin;
while FOverrideActiveRecordBuffer<>nil do
begin
Writer.WriteInteger(ord(FOverrideActiveRecordBuffer^.UpdateStatus));
{$ENDIF}
{$ENDIF}
for i:=0 to nf-1 do
begin
if SaveFields[i]>=0 then
begin
if NewestVersion and Assigned(FOnSaveField) then FOnSaveField(ADataset,i,Fields[i]);
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
{$IFNDEF BINARY_FILE_200_COMPATIBILITY}
{$IFNDEF BINARY_FILE_230_COMPATIBILITY}
Writer.WriteBoolean(Fields[i].IsNull);
if not Fields[i].IsNull then
begin
{$ENDIF}
{$ENDIF}
{$ENDIF}
case Fields[i].DataType of
ftBoolean : Writer.WriteBoolean(Fields[i].AsBoolean);
{$IFNDEF LEVEL3}
ftLargeInt: Writer.WriteFloat(Fields[i].AsFloat);
{$ENDIF}
ftSmallInt,
ftInteger,
ftWord,
ftAutoInc : Writer.WriteInteger(Fields[i].AsInteger);
ftFloat : Writer.WriteFloat(Fields[i].AsFloat);
ftBCD,
ftCurrency : Writer.WriteFloat(Fields[i].AsCurrency);
ftDate,
ftTime,ftDateTime: Writer.WriteFloat(Fields[i].AsFloat);
else
Writer.WriteString(Fields[i].AsString);
end;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
{$IFNDEF BINARY_FILE_200_COMPATIBILITY}
{$IFNDEF BINARY_FILE_230_COMPATIBILITY}
end;
{$ENDIF}
{$ENDIF}
{$ENDIF}
end;
end;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
{$IFNDEF BINARY_FILE_200_COMPATIBILITY} // New for v. 2.24.
// Only write newest version (current data).
if not (sfSaveDeltas in sfDeltas) then break;
// Prepare writing next older version of record.
FOverrideActiveRecordBuffer:=FOverrideActiveRecordBuffer^.PrevRecordVersion;
NewestVersion:=false;
end;
Writer.WriteListEnd;
{$ENDIF}
{$ENDIF}
// Increment save count.
inc(FSaveCount);
end;
Writer.WriteListEnd;
end;
end;
procedure TkbmCustomBinaryStreamFormat.BeforeLoad(ADataset:TkbmCustomMemTable);
begin
inherited;
StreamSize:=WorkStream.Size;
ProgressCnt:=0;
Reader:=TReader.Create(WorkStream,FBuffSize);
Reader.ReadSignature;
InitIndexDef:=false;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
if Reader.NextValue = vaList then // A hack since vaList only exists in >= v. 2.xx.
FileVersion := 100
else
FileVersion:=Reader.ReadInteger;
{$ELSE}
FileVersion:=0;
{$ENDIF}
end;
procedure TkbmCustomBinaryStreamFormat.AfterLoad(ADataset:TkbmCustomMemTable);
begin
Reader.Free;
with TkbmProtCustomMemTable(ADataset) do
begin
// Now create indexes as defined.
if InitIndexDef then CreateIndexes;
FOverrideActiveRecordBuffer:=nil;
end;
inherited;
end;
procedure TkbmCustomBinaryStreamFormat.LoadDef(ADataset:TkbmCustomMemTable);
var
i:integer;
FName,KName,TName,DName,EMask,DExpr:string;
FSize,DSize:integer;
REQ,RO:boolean;
FT:TFieldType;
FK:TFieldKind;
InitTableDef:boolean;
ld:boolean;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
ioptions:TIndexOptions;
FFields:string;
{$ENDIF}
begin
if (StreamSize = 0) then exit;
ld:=sfLoadDef in sfDef;
with TkbmProtCustomMemTable(ADataset) do
begin
// Read all definitions if any saved.
InitTableDef:=false;
InitIndexDef:=false;
try
Reader.ReadListBegin;
while not(Reader.EndofList) do
begin
// Clear previous setup if not cleared yet.
if not InitTableDef then
begin
if ld then
begin
Close;
FieldDefs.clear;
DeleteTable;
end;
InitTableDef:=true;
end;
// read field definition.
FName := Reader.ReadString;
TName := Reader.ReadString;
FSize := Reader.ReadInteger;
DName := Reader.ReadString;
EMask := Reader.ReadString;
DSize := Reader.ReadInteger;
REQ := Reader.ReadBoolean;
RO := Reader.ReadBoolean;
if FileVersion>=250 then KName:=Reader.ReadString
else KName:=FieldKindNames[0]; // fkData
if FileVersion>=251 then DExpr:=Reader.ReadString
else DExpr:='';
// Find fieldtype from fieldtypename.
for i:=0 to ord(High(FieldTypeNames)) do
if FieldTypeNames[TFieldType(i)]=TName then break;
FT:=TFieldType(i);
if not (FT in kbmSupportedFieldTypes) then
raise EMemTableError.Create(Format(kbmUnknownFieldErr1,[TName]));
// Find fieldkind from fieldkindname.
FK:=fkData;
for i:=0 to ord(High(FieldKindNames)) do
if FieldKindNames[i]=KName then
begin
FK:=TFieldKind(i);
break;
end;
if ld then
begin
// Add field definition.
FieldDefs.Add(FName,FT,FSize,REQ);
// Setup other properties.
i:=FieldDefs.IndexOf(FName);
with FieldDefs.Items[i].CreateField(ADataset) do
begin
FieldKind:=FK;
DisplayLabel:=DName;
EditMask:=EMask;
ReadOnly:=RO;
DisplayWidth:=DSize;
{$IFDEF LEVEL4}
DefaultExpression:=DExpr;
{$ENDIF}
end;
end;
end;
Reader.ReadListEnd;
// Indexes introduced in file version 2.00
if FileVersion>=200 then
begin
// Read all index definitions if any saved.
Reader.ReadListBegin;
while not(Reader.EndofList) do
begin
// Clear previous setup if not cleared yet.
if not InitIndexDef then
begin
if ld then
begin
DestroyIndexes;
FIndexDefs.Clear;
end;
InitIndexDef:=true;
end;
// read index definition.
FName := Reader.ReadString;
FFields := Reader.ReadString;
DName := Reader.ReadString;
ioptions:=[];
if Reader.ReadBoolean then ioptions:=ioptions+[ixDescending];
if Reader.ReadBoolean then ioptions:=ioptions+[ixCaseInSensitive];
{$IFNDEF LEVEL3}
if Reader.ReadBoolean then ioptions:=ioptions+[ixNonMaintained];
{$ELSE}
Reader.ReadBoolean; // Skip ixNonMaintained info since not supported for D3/BCB3.
{$ENDIF}
if Reader.ReadBoolean then ioptions:=ioptions+[ixUnique];
// Add field definition.
if ld then
begin
{$IFNDEF LEVEL3}
with IndexDefs.AddIndexDef do
begin
Name:=FName;
Fields:=FFields;
Options:=ioptions;
DisplayName:=DName;
end;
{$ELSE}
IndexDefs.Add(FName,FFields,ioptions);
{$ENDIF}
end;
end;
Reader.ReadListEnd;
end;
finally
if InitTableDef then Open;
end;
end;
if not ld then InitIndexDef:=false;
end;
procedure TkbmCustomBinaryStreamFormat.LoadData(ADataset:TkbmCustomMemTable);
var
i:integer;
nf:integer;
Accept:boolean;
bNull:boolean;
Date:double;
NewestVersion:boolean;
pRec:PkbmRecord;
ApproxRecs:integer;
begin
if (StreamSize = 0) then exit;
with TkbmProtCustomMemTable(ADataset),TkbmProtCommon(ADataset.Common) do
begin
SetTempState(dsinsert);
try
ResetAutoInc;
// Try to determine approx how many records in stream + add some slack.
if RecordSize>0 then
begin
ApproxRecs:=StreamSize div FDataRecordSize;
ApproxRecs:=ApproxRecs + (ApproxRecs div 50) + RecordCount;
end
else
ApproxRecs:=0;
// Read all records.
FLoadCount:=0;
FLoadedCompletely:=true;
if ApproxRecs>0 then FRecords.Capacity:=ApproxRecs; // For speed reason try to preallocate room for all records.
nf:=Fieldcount;
Reader.ReadListBegin;
while not(Reader.EndofList) do
begin
// Show progress.
inc(ProgressCnt);
ProgressCnt:=ProgressCnt mod 100;
if (ProgressCnt=0) then
Progress(trunc((WorkStream.Position / StreamSize) * 100),mtpcLoad);
if (FLoadLimit>0) and (FLoadCount>=FLoadLimit) then
begin
FLoadedCompletely:=false;
break;
end;
pRec:=_InternalAllocRecord;
FOverrideActiveRecordBuffer:=pRec;
NewestVersion:=true;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
{$IFNDEF BINARY_FILE_200_COMPATIBILITY} // New for v. 2.24.
// Loop for all versions of record if versioning is used (2.30 and forth).
if FileVersion>=230 then Reader.ReadListBegin;
while true do
begin
if FileVersion>=230 then FOverrideActiveRecordBuffer^.UpdateStatus:=TUpdateStatus(Reader.ReadInteger);
{$ENDIF}
{$ENDIF}
// Read fields for current record version.
for i:=0 to nf-1 do
begin
//2.50i if Fields[i].FieldKind<>fkData then continue;
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
{$IFNDEF BINARY_FILE_200_COMPATIBILITY}
{$IFNDEF BINARY_FILE_230_COMPATIBILITY} // New for v. 2.49.
// Check if null values saved in binary file.
if (FileVersion>=249) then
bNull:=Reader.ReadBoolean
else
{$ENDIF}
{$ENDIF}
{$ENDIF}
bNull:=false;
// Check if null field.
if bNull then
Fields[i].Clear
else
begin
// Not null, load data.
case Fields[i].DataType of
ftBoolean : Fields[i].AsBoolean := Reader.ReadBoolean;
{$IFNDEF LEVEL3}
ftLargeInt: Fields[i].AsFloat := Reader.ReadFloat;
{$ENDIF}
ftSmallInt,
ftInteger,
ftWord : Fields[i].AsInteger := Reader.ReadInteger;
ftAutoInc : with Fields[i] do begin
AsInteger:=Reader.ReadInteger;
if FAutoIncMax<AsInteger then
FAutoIncMax:=AsInteger;
end;
ftFloat : Fields[i].AsFloat := Reader.ReadFloat;
ftBCD,
ftCurrency : Fields[i].AsCurrency := Reader.ReadFloat;
ftDate,
ftTime,
ftDateTime : begin
Date:=Reader.ReadFloat;
if Date=0 then Fields[i].Clear
else Fields[i].AsFloat:=Date;
end;
else
Fields[i].AsString := Reader.ReadString;
end;
end;
if NewestVersion and Assigned(FOnLoadField) then OnLoadField(ADataset,i,Fields[i]);
{$IFNDEF BINARY_FILE_1XX_COMPATIBILITY}
{$IFNDEF BINARY_FILE_200_COMPATIBILITY} // New for v. 2.24.
end;
// Previous file versions didnt contain versions, so just break loop.
if FileVersion<230 then break;
// Prepare for reading next version if any. (introduced in v. 2.30)
if Reader.EndOfList then break;
// Prepare next version.
NewestVersion:=false;
FOverrideActiveRecordBuffer^.PrevRecordVersion:=_InternalAllocRecord;
FOverrideActiveRecordBuffer:=FOverrideActiveRecordBuffer^.PrevRecordVersion;
end;
if FileVersion>=230 then Reader.ReadListEnd;
{$ENDIF}
{$ENDIF}
Accept:=true;
if Assigned(OnLoadRecord) then OnLoadRecord(ADataset,Accept);
if Accept then
begin
pRec^.RecordID:=FRecordID;
inc(FRecordID);
pRec^.UniqueRecordID:=FUniqueRecordID;
inc(FUniqueRecordID);
pRec^.Flag:=kbmrfInTable;
FRecords.Add(pRec);
if pRec^.UpdateStatus=usDeleted then inc(FDeletedCount);
inc(FLoadCount);
end
else
_InternalFreeRecord(pRec,true,true);
end;
Reader.ReadListEnd;
finally
RestoreState(dsBrowse);
end;
end;
end;
// -----------------------------------------------------------------------------------
// Registration for Delphi 3 / C++ Builder 3
// -----------------------------------------------------------------------------------
{$ifdef LEVEL3}
procedure Register;
begin
RegisterComponents('kbmMemTable', [TkbmBinaryStreamFormat]);
end;
{$endif}
end.