Readkey is NOT working after file is open for reading (assign / reset ) and it does NOT on work after file is closed. Why would opening and closing a file cause Readkey or Readln to not work?
A portion of the program is shown below:
The program uses a simple spreadsheet (a la old VisaCalc) as input/output screen. See
www.rjdesjardins.com for a picture of screen.
User makes changes to screen (some calculations made on the screen with formulas). When the program runs it takes data from the screen, runs the calculations and puts results back on the screen.
When called to RUN (or when called as a HELP screen) it reads a text file and stores the data as properties. When cell B6 is called for HELP it lists all the items, and when Running it gets the properties for the selected item listed in cell B6 and uses the data to make calculations.
Readkey is used several times prior to opening and reading the text file when warning messages are required, and it DOES work to stop the program flow to allow the message to be read and proceeds when any key is pressed. Readkey works up until the text file is opened, and it never goes back to working after the text file is closed. Readkey also will not work when tested within the open and close of the read file, but I don’t need to stop it when reading – I just want it to work afterwards so the program will keep running – it freezes the program the next time Readkey is required. (Readln also does not work).
When the program is first started it opens a file and populates the spreadsheet cells. When the start file closes Readkey works fine. I can also Save and Load a screen and ReadKey works afterwards. But when I read the text file Readkey stops working.
Why would opening and/or closing a read file cause it to fail?
EXAPLE:
{file chelp.pas;} {LAST UPDATE 1/04/93}
Unit CF20help;
{$mode objfpc}{$H+}
INTERFACE
USES CRT,DOS, cf20Var, CF20windo, sysutils ;
procedure GetFillData;
procedure Help;
IMPLEMENTATION
uses CF20_2;
Procedure GetFillData; { This gets input from file of fill data and puts it in an array}
var
S: AnyString;
{FillName = FillList = Array [0..Maxx, BARR..nos] of Real; declared in CF20Var }
{Fd = FillList = Array [0..Maxx, BARR..nos] of Real declared in CF20Var;}
begin
{ Test for Readkey DID work here }
S:='CFlowFil.CFT'; { this is a text file of data in the same folder}
(* Test to see if Readkey works here
gotoXY(75,25); {5 lines to test if Readkey DID work here}
write('CHelp 22');
ch:=readkey;
write(ch); { Readkey did work here with any letter or <return>}
ch:=readkey; { Readkey did work here as the program continued }
*)
Assign (input,'CFlowFil.CFT'); {open CFlowFil.CFT}
try
Reset(input);
i:=-1;
numbob:=0;
While not eof do
begin
i:=i+1;
numbob:=numbob+1;
Readln(FillName[i,Filtype]);
Readln(FillName[i,TestSource]);
Readln(FillName[i,Mfg]);
Readln(FillName[i,Spacing]);
Readln(FillName[i,nozzle]);
Readln(Fd[i,BARR], Fd[i,ARFFF],Fd[i,PP1],Fd[i,PP2],Fd[i,PP3],Fd[i,PP4],Fd[i,PP5],Fd[i,PP6]);
Readln(Fd[i,ACTI],Fd[i,mCTI],Fd[i,Aos],Fd[i,mos],Fd[i,nCTI],Fd[i, nos]);
end; {I know the data file CFlowFil.CFT was read because I can print to screen later}
Close(input); {close CFlowFil.CFT}
Except
gotoXY(75,25);
write('Error closing file'); { This did show on screen}
(* ch:=readkey;
write(ch); {Readkey did NOT work here}
ch:=readkey; {Readkey did NOT work here}
*)
end;
end;
________________________________
Procedure help;
var
OrigMode:Integer;
count:Integer;
begin
count:=0;
OrigMode:=LastMode;
{ Initwindow;
Makewindow(5,1,73,24,4,15);}
clrscr;
if (FX='B') and (FY=6) then {Cell B6 is where the Fill Designation is on the spreadsheet}
begin
Writeln(' Fill Test Manufacturer Sheet Nozzle');
Writeln(' Type Source Spacing Type');
writeln;
GetFillData; {This is the call to Procedure above}
(* gotoXY(75,25);
write('CHelp 162'); {This prints on the screen}
readln; {if readln is used the program just quits}
ch:=readkey;
write(ch); { Readkey did NOT write ch to screen}
ch:=readkey; { Readkey did NOT work here}
*)
i:=-1;
count:=0;
while (i<numbob-1) do
begin
i:=i+1;
count:=count+1;
WriteLN(' '+
FillName[i,Filtype]:10,FillName[i,TestSource]:13,
FillName[i,Mfg]:11, FillName[i,spacing]:9,
FillName[i,nozzle]:12);
if count>15 then {the first 15 does print to screen}
begin
WRITELN;
TEXTCOLOR(YELLOW);
writeln(' PRESS ANY KEY FOR MORE FILL TYPES');
tEXTCOLOR(WHITE);
count:=0;
ch:=readkey; {program stops here because of readkey}
clrscr;
Writeln(' Fill Test Manufacturer Sheet Nozzle');
Writeln(' Type Source Spacing Type');
writeln;
end;
end;
end else
(NOW, PLEASE TELL ME WHY OPENING A FILE “ASSIGN” WOULD NAGATE READEKY ??????????)
In my original post I wrote “ When I used readln in this part of the code I got and error(103) which I think relates to "file not open"?????? I have not gotten that error(103) lately, but maybe it is a clue to what is happening. But, CflowFil.CFT does open, the data is read, and it does close. The original file will run after the read file closes, but it freezes at the first ReadKey.