Results 1 to 5 of 5

Thread: Rudimentary Explaination Needed (Read Command)

  1. #1

    Rudimentary Explaination Needed (Read Command)

    Why is it in Delphi 5.0 that if you run the following code:
    (where iVar is an integer)

    Write('Please Enter An Integer: ');
    Read(iVar);
    Writeln('The Integer You Entered Was: ', iVar);
    Readln;

    The program ignores the Readln; statement. Almost as if the EOLN entered for the Read gets passed onto the Readln. If this is the case... is there anyway to prevent this from happening? I find it hard to believe that this input would in some was be buffered up and held, then used by the Readln later on.
    My DGDev forum pascal syntax highlight settings:
    <br />[background=#FFFFFF][comment=#8080FF][normal=#000080]
    <br />[number=#C00000][reserved=#000000][string=#00C000]

  2. #2
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Rudimentary Explaination Needed (Read Command)

    This is correct. Read:

    As the help says:
    Read reads all characters up to, but not including, the next end-of-line marker or until Eof(F) becomes true; it does not skip to the next line after reading. If the resulting string is longer than the maximum length of the string variable, it is truncated.
    After the first Read, each subsequent Read sees the end-of-line marker and returns a zero-length string.
    Use multiple Readln calls to read successive string values.
    So the end-of-lin marker is still in the buffer and read immediatly by ReadLn.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  3. #3

    Rudimentary Explaination Needed (Read Command)

    Okay, simple enough. But second question... is there a way to do a system("PAUSE") in Delphi? I've done it in C, so I'm hoping there is some equivalent, other than readln.
    My DGDev forum pascal syntax highlight settings:
    <br />[background=#FFFFFF][comment=#8080FF][normal=#000080]
    <br />[number=#C00000][reserved=#000000][string=#00C000]

  4. #4
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Rudimentary Explaination Needed (Read Command)

    Not sure exactly what you want - Do you want a sleep function or wit for the next input from the user?
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  5. #5

    Rudimentary Explaination Needed (Read Command)

    Well I was using Readln to pause for "ENTER" to close out the application. But seeing as a Read before a Readln basically voids that Readln, the app was just closing without pausing... so I needed two Readlns to pause. What I want is a single standard way to pause at the end of an app, that isn't dependant on what has come before it in the code...

    Update: it looks like if I Reset(input) before I use Readln to pause, it eliminates the EOLN that was getting passed on. So I should be able to create a procedure that does just that, and name it Pause. Of course, that could cause trouble if used somewhere other than the end of the application, as I'm basically flushing the input buffer... but not handling for any data that might be queued up.
    My DGDev forum pascal syntax highlight settings:
    <br />[background=#FFFFFF][comment=#8080FF][normal=#000080]
    <br />[number=#C00000][reserved=#000000][string=#00C000]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •