Readln in lazarus pascal not working lazarus / 62-General ---------------------------------------------------------------------- SW48 · 2019-11-04 17:40 When I writeln('enter number'); readln(number); writeln('enter number2'); readln(number2); it asks for the number and I type it and it reads it upon hitting return as it should. The second writeln shows on screen but when I type a number it doesn't show on the keyboard unless I type it a second time. Any idea why this is happening? ---------------------------------------------------------------------- winni · 2019-11-04 18:15 Hi! Your terminal window or cmd window is not high enough. Expand it to full screen. Or: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i write('enter number:  ');readln(number);write('enter number2:  ');readln(number2);  Winni ---------------------------------------------------------------------- SW48 · 2019-11-04 23:15 Thank you very much for the response but neither of them worked. Do you have anything else you can think of for me to try? ---------------------------------------------------------------------- jamie · 2019-11-04 23:39 what OS are you on and can you please post the complete lines here ? Btw, if that is the last line of the program and you are in console mode it seems, you need to place a readln as the last function so the console screen will stay open and wait for you to hit enter. ---------------------------------------------------------------------- SW48 · 2019-11-04 23:45 Thanks. Windows 10 version 1903 This happens with every keyboard input after the first one which works fine.  The rest of them I have to type the number or letter a second time before it shows up on the screen and can be read in. Actual Code is: Write('Choose the Home team by number and hit enter  ');   Readln(teamnumber);   HomeTeamAcronym := teamacronym[teamnumber];   t1 := teamnamelist[teamnumber];   Write('Choose the Visiting team by number and hit enter  ');   Readln(teamnumber);   VisitingTeamAcronym := teamacronym[teamnumber]; ---------------------------------------------------------------------- winni · 2019-11-04 23:58 Hi! Yeah, that's the trick - what Jamie said about the last line of code. In the tradition of the 80s the last three lines of code have to look like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i writeln ('Thats all folks ......');readln;end. Buena note Winni ---------------------------------------------------------------------- SW48 · 2019-11-05 00:12 I have the code you show here as my last 3 lines. What I am referring to is early in a 10,000 line program where I am inputting what teams I want to use for a game. The first writeln and readln the input number shows up on the screen on the first keystroke. The second writeln and readlin I have to press the number on the keyboard twice for it to show up on the screen. Now if I press 1 for team 1 and then hit enter twice then press 2 for team 2.  The 2 does show up on the screen on the first press. But this code is nowhere near the end of the program.  It is at the very beginning and there are keyboard inputs throughout the entire program. ---------------------------------------------------------------------- SW48 · 2019-11-05 00:19 I think I solved it. If I right click in the upper left corner of the command prompt and select "properties" then "Use Legacy Console" it works properly with my pascal programs. Thanks everyone for giving me ideas on the fix. ---------------------------------------------------------------------- SW48 · 2019-11-05 00:22 I spoke too soon.  It still doesn't work. I have to type 1 then enter then either enter or type 2 twice...sigh ---------------------------------------------------------------------- 440bx · 2019-11-05 01:49 Quote from: SW48 on November 05, 2019, 01:22:26 amI have to type 1 then enter then either enter or type 2 twice...sigh What you describe sounds like there is an extra (unwanted) "read" somewhere in your code. Can you reproduce the problem in a short, standalone program ?  If you could post a short program that exhibits the problem, it would be easier to determine the cause. ---------------------------------------------------------------------- Thaddy · 2019-11-05 06:09 complete version:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program numbers;{$ifdef mswindows}{$apptype console}{$endif}var number,number2:integer;begin  writeln('enter number');  readln(number);  writeln('enter number2');  readln(number2);  writeln(number);  writeln(number2);end.Works (of course.....).... Note Lazarus is -still - not really friendly with console programs and you should never (almost never) use such code in a GUI app if that is your confusion. ---------------------------------------------------------------------- SW48 · 2019-11-05 13:23 Thanks! When I run your program it works! Now I have to figure out why mine doesn't. Maybe its the top line:  {$ifdef mswindows}{$apptype console}{$endif} ---------------------------------------------------------------------- SW48 · 2019-11-05 13:33 Quote from: Thaddy on November 05, 2019, 07:09:54 amcomplete version:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program numbers;{$ifdef mswindows}{$apptype console}{$endif}var number,number2:integer;begin  writeln('enter number');  readln(number);  writeln('enter number2');  readln(number2);  writeln(number);  writeln(number2);end.Works (of course.....).... Note Lazarus is -still - not really friendly with console programs and you should never (almost never) use such code in a GUI app if that is your confusion. Is anyone able to look at my code and find the error for a small paypal donation? ---------------------------------------------------------------------- lainz · 2019-11-05 13:53 Yes debugging is hard, but is something you must learn to do. Try adding extra writeln in your code to see where it fails. Maybe you're using just write instead of writeln? ---------------------------------------------------------------------- SW48 · 2019-11-05 14:20 When I debug and step into it line by line it works fine. When I take the debug step by step out, it does not work and I have to type the number twice. I've used pascal since 1988 and have never seen anything like this. ---------------------------------------------------------------------- SW48 · 2019-11-05 14:28 Quote from: Thaddy on November 05, 2019, 07:09:54 amcomplete version:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program numbers;{$ifdef mswindows}{$apptype console}{$endif}var number,number2:integer;begin  writeln('enter number');  readln(number);  writeln('enter number2');  readln(number2);  writeln(number);  writeln(number2);end.Works (of course.....).... Note Lazarus is -still - not really friendly with console programs and you should never (almost never) use such code in a GUI app if that is your confusion. If I put your code in a new program it works fine. If I paste it into my program it gives the same problem.  Enter number and I type 1 it takes it correctly.  Enter number2 and I press 2, nothing shows up, I have to type 2 a second time. ---------------------------------------------------------------------- 440bx · 2019-11-05 14:29 Quote from: SW48 on November 05, 2019, 02:23:37 pmMaybe its the top line:  {$ifdef mswindows}{$apptype console}{$endif} Very doubtful that is the cause of the problem.  Quote from: SW48 on November 05, 2019, 02:33:07 pmIs anyone able to look at my code and find the error for a small paypal donation? It's quite likely that there are a good number of forum members that will look at your code just for the pleasure of helping.  IOW, you probably don't need to offer a paypal donation.  BUT, if you're willing to offer a "small" million euros, no doubt you'll get plenty of help Just post or attach the code to your next post. ---------------------------------------------------------------------- SW48 · 2019-11-05 14:48 Here is the code attached. And I will attach the input file in the next post ---------------------------------------------------------------------- SW48 · 2019-11-05 14:48 Here is the input file ---------------------------------------------------------------------- 440bx · 2019-11-05 16:21 The problem is caused by an error in the drivers unit.  The solution is: 1. Comment out the "drivers" unit from the "uses" list.  IOW, your program should _no_ longer be using "drivers". 2. Comment out the line "InitVideo" at the beginning of your program. After that, your program will work as expected. HTH. ---------------------------------------------------------------------- howardpc · 2019-11-05 16:25 Beyond the problem with "drivers" and InitVideo,  there are various unsatisfactory features of your coding. However, if you get rid of all the shortstrings (replacing simply with String), you will have already started to improve things (some of your string literals are longer than the shortstrings you stuff them into). Did you know your code abounds in unused variables, unused parameters and code that is never used or called? ---------------------------------------------------------------------- SW48 · 2019-11-05 16:37 Quote from: 440bx on November 05, 2019, 05:21:38 pmThe problem is caused by an error in the drivers unit.  The solution is: 1. Comment out the "drivers" unit from the "uses" list.  IOW, your program should _no_ longer be using "drivers". 2. Comment out the line "InitVideo" at the beginning of your program. After that, your program will work as expected. HTH. Thank you SO MUCH! And thank you to everyone that helped. Send me a PM with your paypal ---------------------------------------------------------------------- SW48 · 2019-11-05 16:39 Quote from: howardpc on November 05, 2019, 05:25:51 pmBeyond the problem with "drivers" and InitVideo,  there are various unsatisfactory features of your coding. However, if you get rid of all the shortstrings (replacing simply with String), you will have already started to improve things (some of your string literals are longer than the shortstrings you stuff them into). Did you know your code abounds in unused variables, unused parameters and code that is never used or called? Yes, this is a program that plays a football board game called strat- o-matic and keeps stats etc so it can be played faster. I started this in the 1990's using turbo pascal so the code is all over the place.  I will replace the shortstrings, thanks ---------------------------------------------------------------------- SW48 · 2019-11-05 16:40 Quote from: howardpc on November 05, 2019, 05:25:51 pmBeyond the problem with "drivers" and InitVideo,  there are various unsatisfactory features of your coding. However, if you get rid of all the shortstrings (replacing simply with String), you will have already started to improve things (some of your string literals are longer than the shortstrings you stuff them into). Did you know your code abounds in unused variables, unused parameters and code that is never used or called? Actually when I search shortstring I don't find anything, or do you mean string[5] for example? ---------------------------------------------------------------------- 440bx · 2019-11-05 16:40 Quote from: SW48 on November 05, 2019, 05:37:25 pmThank you SO MUCH! And thank you to everyone that helped. Send me a PM with your paypal You're welcome and just use the paypal money to get yourself a drink on me.  Cheers! ---------------------------------------------------------------------- howardpc · 2019-11-05 16:55 Quote from: SW48 on November 05, 2019, 05:40:38 pmActually when I search shortstring I don't find anything, or do you mean string[5] for example? Yes, all instances of string[xx] are shortstring declarations. Simply replace all of them with string, along with the compiler directive {$H+} at the top of your program. For instance you can removeCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   NameArray = string[24];   TeamAcronymArray = string[3];altogether, and simply declare all NameArray and TeamAcronymArray variables as string (or AnsiString which is the same thing under {$H+}). ---------------------------------------------------------------------- Thaddy · 2019-11-05 17:24 Quote from: 440bx on November 05, 2019, 03:29:38 pm BUT, if you're willing to offer a "small" million euros, no doubt you'll get plenty of help Naahh....