Recent

Author Topic: Readln in lazarus pascal not working  (Read 2142 times)

SW48

  • New Member
  • *
  • Posts: 36
Re: Readln in lazarus pascal not working
« Reply #15 on: November 05, 2019, 03:28:16 pm »
complete version:
Code: Pascal  [Select][+][-]
  1. program numbers;
  2. {$ifdef mswindows}{$apptype console}{$endif}
  3. var
  4.  number,number2:integer;
  5. begin
  6.   writeln('enter number');
  7.   readln(number);
  8.   writeln('enter number2');
  9.   readln(number2);
  10.   writeln(number);
  11.   writeln(number2);
  12. 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

  • Hero Member
  • *****
  • Posts: 2170
Re: Readln in lazarus pascal not working
« Reply #16 on: November 05, 2019, 03:29:38 pm »
Maybe its the top line:  {$ifdef mswindows}{$apptype console}{$endif}
Very doubtful that is the cause of the problem. 

Is 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.

FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

SW48

  • New Member
  • *
  • Posts: 36
Re: Readln in lazarus pascal not working
« Reply #17 on: November 05, 2019, 03:48:14 pm »
Here is the code attached.

And I will attach the input file in the next post

SW48

  • New Member
  • *
  • Posts: 36
Re: Readln in lazarus pascal not working
« Reply #18 on: November 05, 2019, 03:48:40 pm »
Here is the input file

440bx

  • Hero Member
  • *****
  • Posts: 2170
Re: Readln in lazarus pascal not working
« Reply #19 on: November 05, 2019, 05:21:38 pm »
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.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

howardpc

  • Hero Member
  • *****
  • Posts: 3644
Re: Readln in lazarus pascal not working
« Reply #20 on: November 05, 2019, 05:25:51 pm »
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

  • New Member
  • *
  • Posts: 36
Re: Readln in lazarus pascal not working
« Reply #21 on: November 05, 2019, 05:37:25 pm »
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.

Thank you SO MUCH!

And thank you to everyone that helped.

Send me a PM with your paypal

SW48

  • New Member
  • *
  • Posts: 36
Re: Readln in lazarus pascal not working
« Reply #22 on: November 05, 2019, 05:39:00 pm »
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?

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

  • New Member
  • *
  • Posts: 36
Re: Readln in lazarus pascal not working
« Reply #23 on: November 05, 2019, 05:40:38 pm »
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?

Actually when I search shortstring I don't find anything, or do you mean string[5] for example?

440bx

  • Hero Member
  • *****
  • Posts: 2170
Re: Readln in lazarus pascal not working
« Reply #24 on: November 05, 2019, 05:40:57 pm »
Thank 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!
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

howardpc

  • Hero Member
  • *****
  • Posts: 3644
Re: Readln in lazarus pascal not working
« Reply #25 on: November 05, 2019, 05:55:18 pm »
Actually 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 remove
Code: Pascal  [Select][+][-]
  1.   NameArray = string[24];
  2.  
  3.   TeamAcronymArray = string[3];
altogether, and simply declare all NameArray and TeamAcronymArray variables as string (or AnsiString which is the same thing under {$H+}).

Thaddy

  • Hero Member
  • *****
  • Posts: 10704
Re: Readln in lazarus pascal not working
« Reply #26 on: November 05, 2019, 06:24:55 pm »
BUT, if you're willing to offer a "small" million euros, no doubt you'll get plenty of help ;)
Naahh....

 

TinyPortal © 2005-2018