Application Error ved skrivning til fil
Hej!Min kode generere en application Error når den fil jeg skriver til lukkes til aller sidst i proceduren. Men kun hvis den fil jeg henter dataen fra er stører en min read/write-buffer (buf). Hvordan kan jeg undgå det?
procedure TForm1.EncryptFile1Click(Sender: TObject);
var
numRead, numWritten,i, charNum, codeCount, counter, enum, codeNum: integer;
buf, outbuf : array[1..2048] of Char;
currentChar : char;
begin
if length(codeText.Text) > 0 then
if SD1.Execute then
begin
assignFile(toF,SD1.FileName);
rewrite(toF,1);
begin
if OD1.Execute then
begin
assignFile(fromF, OD1.FileName);
reset(fromF,1);
end
else
begin
reset(fromF,1);
end;
Repeat
predefine;
BlockRead(fromF, buf, SizeOf(buf), NumRead);
begin
codeCount := 1;
for i := 0 to length(buf) do
if inArray(buf[i]) then
begin
charNum := lord(buf[i]);
if codeCount = length(code) then
begin
codeCount := 1;
end
else
begin
codeCount := codeCount+1;
end;
codeNum := ord(code[codeCount])+round((power(sin(codeCount)*10,3)/4)+(100-codeCount));
enum := charNum+codeNum;
outbuf[i] := lchar(enum);
end
else
begin
outbuf[i] := buf[i];
end;
end;
blockWrite(ToF, outBuf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(fromF);
CloseFile(toF);
end;
end;
end;