PDA

View Full Version : Exiting Readln Statement...



DarknessX
03-05-2007, 12:31 AM
Hey guys... Yet another question...
I want to make a main program loop that constantly checks the time, date, and day (date and day will only be checked when the time hits 12:00am) to trigger a timer, but it will accept input at the end of each repeat. Now, my problem, is that as long as nobody types anything, the loop sticks where it is at the readln(); statement until someone hits enter...

How would I fix this? Is there any way to make one program executing 2 commands at the same time? (I'm thinking multi-threaded, but I'm really not sure...)

Robert Kosek
03-05-2007, 02:09 AM
Grr, I used to know how to do this. Honestly Delphi isn't made for console applications, you're better off with FPC for that.

Read/ReadLn do not exit until input, and the latter requires an EOL character/input for completion. I used to have a sort of "GetKey" statement that let me wait around until there was a key pressed, and then read the key from the buffer. But I can't remember, sorry. I also can't find anything helpful via Google.

I think you're out on a limb here unless someone has a personal method or something special. I highly advise against going multithreaded in a console application unless you intend to write methods to "lock" the read/write statements. Otherwise you'll make your own nasty can of worms.

DarknessX
03-05-2007, 10:50 AM
I'm not using Delphi, I'm using FPC.

Robert Kosek
03-05-2007, 11:10 AM
...You never said that in your original post. That kind of stuff helps, as I don't read every other post on the forum. Don't have the time anymore.

RTL.pdf, pages 373-374



while not exit do begin
if KeyPressed then
exit := ReadKey in [' ',#13,#10];

// ... Date stuff
end;