Author: Tomas Rutkauskas
How to calculate the size of a record
Answer:
Here's some code where StrucGrid is a StringGrid holding the table structure in
DBD-like single char indentifiers in Col1 and, if applicable, field size in Col2.
SpinEdit2 holds the blocksize in byte.
1
2 procedure TMainFrm.CalculateRecordSizeClick(Sender: TObject);
3 var
4 MaxRecs, RecSize, RecsPerBlock, FreeSpace: Longint;
5 i: Integer;
6 begin
7 RecSize := 0;
8 with StrucGrid do
9 begin
10 for i := 0 to pred(RowCount) do
11 begin
12 case Cells[1, i][1] of
13 'A': RecSize := RecSize + StrToInt(Cells[2, i]);
14 'D', 'T', 'I', '+': RecSize := RecSize + 4;
15 'N', '$', 'Y', '@': RecSize := RecSize + 8;
16 'M', 'B', 'F', 'O', 'G': RecSize := RecSize + 10 + StrToInt(Cells[2, i]);
17 'S': RecSize := RecSize + 2;
18 'L': RecSize := RecSize + 1;
19 end;
20 end;
21 end;
22 RecsPerBlock := (SpinEdit2.Value - 6) div RecSize;
23 FreeSpace := (SpinEdit2.Value - 6) - (RecSize * RecsPerBlock);
24 MaxRecs := 65536 * RecsPerBlock;
25 ShowMessage('Record Size is: ' + IntToStr(RecSize) + ' bytes' + #13#10
26 + 'Records per Block: ' + IntToStr(RecsPerBlock) + #13#10
27 + 'Unused Space per Block: ' + IntToStr(FreeSpace) + ' bytes' + #13#10
28 + 'Max No of Records in Table: ' + FormatFloat('###############,', MaxRecs));
29 end;
|