4. procedure TfrmFileMngm.btnConvClick(Sender: TObject);
begin
if odCars.Execute then
if not Cars.Convert(odCars.FileName, sgErr) then
begin
lblErr.Visible := true;
sgErr.Visible := true;
btnClean.Visible := true;
end;
end;
procedure TfrmFileMngm.btnLoadClick(Sender: TObject);
begin
if odCars.Execute then
Cars.Load(odCars.FileName, sgCars);
end;
5. type
TCar = record
Mark : string[25];
V : single;
S : integer;
end;
TCars = array of TCar;
TCarsMngm = class
fCarsTxt : text;
bCarsTxt : string;
fCars : file of TCar;
bCars : TCar;
Cars : TCars;
function ConvertRec : integer;
function Convert (_fIn : string; var _Err : TStringGrid) : boolean;
procedure Load(_fIn : string; var _Cars : TStringGrid);
end;
6. function TCarsMngm.Convert(_fIn : string; var _Err : TStringGrid) : boolean;
var
Cnv : integer;
Res : boolean;
S:string;
begin
Cnv := 0;
AssignFile(fCarsTxt, _fIn);
reset(fCarsTxt);
S:=copy(_fIn, 1, length(_fIn) - 7) + 'dat';
AssignFile(fCars, S);
rewrite(fCars);
Res := true;
while not eof(fCarsTxt) do
begin
readln(fCarsTxt, bCarsTxt);
Cnv := ConvertRec;
Res := Res and (Cnv = 0);
8. function TCarsMngm.ConvertRec : integer;
var
tmp : string;
begin
tmp := bCarsTxt;
if Pos('' , tmp) > 0 then
begin
bCars.Mark := copy(tmp, 1, Pos('' , tmp) - 1);
delete(tmp, 1, Pos('' , tmp));
if Pos('' , tmp) > 0 then
begin
if TryStrToFloat(copy(tmp, 1, Pos('' , tmp) - 1), bCars.V) then
begin
delete(tmp, 1, Pos('' , tmp));
if TryStrToInt(tmp, bCars.S) then
ConvertRec := 0
else
ConvertRec := 2;
end
else
ConvertRec := 1;
end
else
ConvertRec := 3;
end
else
ConvertRec := 3;
end;
9. procedure TCarsMngm.Load(_fIn : string; var _Cars: TStringGrid);
var
i : integer;
begin
AssignFile(fCars, _fIn);
reset(fCars);
_Cars.RowCount := FileSize(fCars) + 1;
i:=0;
while not eof(fCars) do
begin
read(fCars, bCars);
i := i+1;
_Cars.Cells[0,i] := bCars.Mark;
_Cars.Cells[1,i] := FloatToStr(bCars.V);
_Cars.Cells[2,i] := IntToStr(bCars.S);
end;
close(fCars);
end;
10. type
TProductComposition=record
Product,
{ изделие-узел}
Element : string[25];
{ узел-деталь }
Quantity : integer;
{ количество }
end;
TCorrProductComposition=class
fProductComposition:file of TProductComposition;
bProductComposition:TProductComposition;
fProof:file of TProductComposition;
bProof:TProductComposition;
fCorr:file of TProductComposition;
bCorr:TProductComposition;
procedure ConvProdComp;
procedure ConvProof;
procedure Correct;
procedure ShowCorr(var _Res:TStringGrid;_f:integer);
function Compare:integer;
end;
11. function TCorrProductComposition.Compare: integer;
begin
if bProductComposition.Product < bProof.Product then
Compare := 0
else
if bProductComposition.Product = bProof.Product then
if bProductComposition.Element < bProof.Element then
Compare := 0
else
if bProductComposition.Element = bProof.Element then
Compare := 1
else
Compare := 2
else
Compare :=2 ;
end;
12. function TMerge.Compare(_Scoop:boolean): integer;
var
KeyBucket, KeyFile: shortstring;
begin
with Bucket do
KeyBucket:=Format('%2d%100s%2d',[Grade,Theme,ComplexityLevel]);
if _Scoop then
with bStudents do
KeyFile:=Format('%2d%100s%2d',[Grade,Theme,ComplexityLevel])
else
with bProblemPool do
KeyFile:=Format('%2d%100s%2d',
[Grade,Theme,Problem.ComplexityLevel]);
if KeyBucket < KeyFile then
Compare:=0
else
if KeyBucket = KeyFile then
Compare:=1
else
Compare:=2;
end;
15. procedure TCarsMngm.HCreate(_fIn: string);
var
i: integer;
begin
AssignFile(fCars, _fIn);
reset(fCars);
AssignFile(fHash, copy(_fIn, 1, pos('.', _fIn)) + 'hsh');
rewrite(fHash);
bCars.Mark := '';
bCars.V := 0;
bCars.S := 0;
for i := 1 to H do
write(fHash, bCars);
reset(fHash);
while not eof(fCars) do
begin
read(fCars, bCars);
seek(fHash, Hash(bCars.Mark));
write(fHash, bCars);
end;
close(fHash);
end;