MacOS LazFPC 40RC2/323
The program re-write I am working on requires that I log inverter data every 1 minute to text files. There are 16 log files. The inverter data that is being read will be stored in a record or array. It seems that from an efficiency point of view a good approach is to open all the files at start of program and leave them open thus avoiding resource expensive open/close operations.
While considering how to program this other than a list of statements for open, update and then close it occurred to me that I am dealing with 16 identical processes so why not place them in arrays. The following code snippet shows what I have tried. While I did not expect it to work it does but I don't understand why. The line that puzzles me is
arFile: Array[1..3] Of TextFile;
because I don't initialise the contents of arFile thus I would have expected that each element is null but I do end up with multiple files being created as desired.
Have I been lucky that my code snippet works? Is there a better/safer way to code this task?
Var
i: Int32;
num: Single;
arFile: Array[1..3] Of TextFile;
arFileName: Array[1..3] Of String;
Begin
for i:= 1 to 3 do
begin
arFileName[i]:= g.DebugLogFilePath + '/File' + IntToStr(i) + '.cht';
assignFile(arFile[i],arFileName[i]);
ReWrite(arFile[i]);
end;
For i:= 1 to 3 do
Begin
writeln(arFile[i], 'Hello textfile!');
writeln(arFile[i], 'Hello textfile Line two');
CloseFile(arFile[i]);
end;