Recent

Author Topic: Console programs [SOLVED]  (Read 514 times)

pascal111

  • Sr. Member
  • ****
  • Posts: 282
  • Un trabajo en equipo para programas serias.
Console programs [SOLVED]
« on: May 11, 2021, 04:06:20 pm »
أُريد تنفيذ بعض البرامج على الـ console أي برامج بدون واجهة إستخدام رسوميّة GUI مثل البرنامج التالي كنموذج بسيط لطباعة بعض العبارات ولقد إخترت خيار Program من القائمة المعروضة لإنشاء مشروع جديد Create a new project وقُمتُ بتنفيذ البرنامج ولكن لم أرى نتيجة التنفيذ على الـ console ولا شاشة أو نافذة الـ console نفسها.

google translate:

"I want to implement some programs on the console, i.e. programs without a GUI, such as the following program as a simple form to print some statements and I chose the Program option from the displayed menu to create a new project and I executed the program but I did not see the result of the implementation on the console nor a screen or The console window itself."


Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes
  10.   { you can add units after this };
  11.  
  12. begin
  13.  
  14.   write('Do you think if you encouraged me to seek money');
  15.   write('that I''ll have some?!!');
  16.   writeln('It doesn''t work as you think.');
  17. end.
  18.  
  19.  
« Last Edit: May 11, 2021, 05:09:05 pm by pascal111 »

wp

  • Hero Member
  • *****
  • Posts: 8351
Re: Console programs
« Reply #1 on: May 11, 2021, 04:24:06 pm »
I think you are on Windows. When you run your program out of Lazarus the console is opened, the program is executed and the console closes automatically. This is so fast that one might think that nothing did happen. Of course, when you run your program from a console window directly then you do see the output.

What I always do is to add a Readln at the end of the console program, at least for testing purposes. Then the user must press ENTER to close the console:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes
  10.   { you can add units after this };
  11.  
  12. begin
  13.  
  14.   write('Do you think if you encouraged me to seek money');
  15.   write('that I''ll have some?!!');
  16.   writeln('It doesn''t work as you think.');
  17.  
  18.   WriteLn;
  19.   WriteLn('Press ENTER to close the progam.');
  20.   ReadLn;
  21. end.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

pascal111

  • Sr. Member
  • ****
  • Posts: 282
  • Un trabajo en equipo para programas serias.
Re: Console programs
« Reply #2 on: May 11, 2021, 04:32:18 pm »
I think you are on Windows. When you run your program out of Lazarus the console is opened, the program is executed and the console closes automatically. This is so fast that one might think that nothing did happen. Of course, when you run your program from a console window directly then you do see the output.

What I always do is to add a Readln at the end of the console program, at least for testing purposes. Then the user must press ENTER to close the console:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes
  10.   { you can add units after this };
  11.  
  12. begin
  13.  
  14.   write('Do you think if you encouraged me to seek money');
  15.   write('that I''ll have some?!!');
  16.   writeln('It doesn''t work as you think.');
  17.  
  18.   WriteLn;
  19.   WriteLn('Press ENTER to close the progam.');
  20.   ReadLn;
  21. end.

قُمتُ بإضافة ما قد نصحت به ولكن لا يزال الوضع كما هو عليه ،لا تغيير ولكنّ بيئة Lazarus هذه المرّة إنتظرت منّي ضغط زر توقف في الـ debug.

google translate:

"I added what I you advised but the situation is still the same, no change, but the Lazarus environment this time waited for me to press the pause "stop" button in "of" the debug."

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7149
  • Debugger - SynEdit - and more
    • wiki
Re: Console programs
« Reply #3 on: May 11, 2021, 04:43:27 pm »
The Readln is for Windows only.

On Linux: menu > View > Debug Windows > Console output

On Mac:
menu > Tools > options > Debugger => in the property grid: "LaunchNewTerminal" = True
(But that will affect all apps. So you get a terminal for GUI apps too. And you must close the terminal yourself when the app exited)

pascal111

  • Sr. Member
  • ****
  • Posts: 282
  • Un trabajo en equipo para programas serias.
Re: Console programs
« Reply #4 on: May 11, 2021, 05:06:28 pm »
The Readln is for Windows only.

On Linux: menu > View > Debug Windows > Console output

On Mac:
menu > Tools > options > Debugger => in the property grid: "LaunchNewTerminal" = True
(But that will affect all apps. So you get a terminal for GUI apps too. And you must close the terminal yourself when the app exited)

كلامكـ صائب كما في الصورة التاليّة. تفاصيل دقيقة مُفيدة ،أشكُركـ!

google translate:

"Your words are correct, as in the following picture "image". Helpful minute "accurate" details, thank you!"

(https://i.postimg.cc/py5X7VyC/Screenshot-at-2021-05-11-17-02-47.png)

 

TinyPortal © 2005-2018