Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-10

Better Alternative to delay()

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

George Patterson

Hi all,

I am using the delay function to pause for an amount of time which works but will not allow the user to stop the program from the console, using ctrl-C. If I could trap the keystroke, I would be happy.

Excuse the indentation...

while not eof(sin) do
    begin
        repeat
           readln (sin, line);
 	   writeln (line);
	   //readln(input_text);
	   delay(250); //time is measured in milliseconds
	   input_text:='hello';
	   writeln(sout,input_text);
	until keypressed;
    end;
close (sin);

What is a better way to write that code snippet. The delay does not need to be accurate (quarter of a second will not matter)..

Thanks

George Patterson

Reply by email

Darek Mazur
to George Patterson

The better way is write your own function to input data from keybord Then You may wait so long as you want, trap special keys etc

for exaple

function inputkstring(wait : longint):string;
var
  s  : string;
  ch : char;
  theend : boolean;
begin
  s:='';
 theend:=false;
  repeat
   delay(100);
   if not keypressed then contiue;
   ch:=readkey;
   if ch = ....... then theend:=true
; others case
   else s:=s+ch;
  until theend;
end;
Earlier message 39 lines
----- Original Message ----- From: "George Patterson" To: Sent: Wednesday, October 15, 2003 6:29 AM Subject: [fpc-pascal]Better Alternative to delay() > Hi all, > > I am using the delay function to pause for an amount of time which works > but will not allow the user to stop the program from the console, using > ctrl-C. If I could trap the keystroke, I would be happy. > > Excuse the indentation... > > while not eof(sin) do > begin > repeat > readln (sin, line); > writeln (line); > //readln(input_text); > delay(250); //time is measured in milliseconds > input_text:='hello'; > writeln(sout,input_text); > until keypressed; > end; > close (sin); > > > What is a better way to write that code snippet. The delay does not need > to be accurate (quarter of a second will not matter).. > > Thanks > > George Patterson > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Arne Hanssen
to George Patterson: I am using the delay function to pause for an amount of time which works but will not…
George Patterson wrote 18 lines
Hi all, I am using the delay function to pause for an amount of time which works but will not allow the user to stop the program from the console, using ctrl-C. If I could trap the keystroke, I would be happy. Excuse the indentation... while not eof(sin) do begin repeat readln (sin, line); writeln (line); //readln(input_text); delay(250); //time is measured in milliseconds input_text:='hello'; writeln(sout,input_text); until keypressed;

if ReadKey = [CTRL-C] then ...

end; close (sin);

Untested and somewhat wrong syntax, but if I understand your question correctly, ReadKey should be what you are looking for.

Vennlig hilsen / Best regards Arne Hanssen

Reply by email