Possible to build a hybrid (Console/GUI)? lazarus / 34-Windows ---------------------------------------------------------------------- Ozz_Nixon · 2023-04-08 16:43 I have tried many different attempts, without success, without success. So, I will just ask the group. I would like to build an application that looks like a DOS Console, however, with an associated TForm. All from one EXE, is this possible? Can someone explain how to design it? File -> New -> (What choice??) ---------------------------------------------------------------------- MarkMLl · 2023-04-08 18:39 It definitely is for unix-style OSes, I'd not like to comment on Windows but I suggest taking a look at the .lpr file in https://github.com/MarkMLl/Mastech_ms2115b or https://github.com/MarkMLl/Contec_cms50dplus What I've done there is to say that if there are parameters (including the special cases of --help or --version) on the command line then run as a text-mode program, otherwise with a GUI. MarkMLl ---------------------------------------------------------------------- 440bx · 2023-04-08 20:48 Quote from: ozznixon on April 08, 2023, 06:43:14 pmI would like to build an application that looks like a DOS Console, however, with an associated TForm. All from one EXE, is this possible? The following comments apply to Windows only.  That's something I've played with in the past and it is possible only to a _limited_ extent. Here are some of the problems you'll face: If the app is a GUI trying to mimic a console, the first problem it will run into is that Windows will NOT redirect its output (being a GUI, its window cannot be redirected), also piping is out of the question since it doesn't make sense to pipe the output of a GUI app to a file. Another problem such an app will face is that if it is started from a command line that invokes the app for every instance of a file, the command line interpreter will NOT wait for the app to finish before it starts another instance of the same app for the next file.  IOW, if the command is to execute the app for every file in a directory and the directory contains 10,000 files, 10,000 copies of the GUI will be started (Windows goes nuts before the 10,000 copies are instanced.) These problems can be solved to _some_ extent but not completely and, even a partial solution is very difficult to implement correctly.  There is one attempt somewhere on the net and it works as long as you are "very nice" to it (and it doesn't do redirection, much less piping.)  I don't remember where I saw it but, if you search hard enough, I'm sure you'll find it. Those two are the biggest problems a GUI trying to mimic a console app faces. Now, if the app is a console app trying to mimic a GUI app, it's either very simple or impossible depending on the desired behavior.  The first problem is that if the app is started from a console, that console will not be available again until the app close (which wouldn't happen with a GUI app.)  There is also no way (normally) to prevent the console from showing/flashing on the screen before a GUI windows is opened.  IOW, it's "unsightly". Conclusion: at least in Windows, there will always be obvious tell- tale signs to clearly indicate that the app is a console or a GUI. ---------------------------------------------------------------------- KodeZwerg · 2023-04-08 21:12 Quote from: ozznixon on April 08, 2023, 06:43:14 pmI have tried many different attempts, without success, without success. So, I will just ask the group. I would like to build an application that looks like a DOS Console, however, with an associated TForm. All from one EXE, is this possible? Can someone explain how to design it? File -> New -> (What choice??) What have you tried and how? How you mean it, associated TForm? If you explain what's your actual task then we could maybe push you to the right direction or explaining that it is not possible from way of your understanding what's a console and a GUI app is. ---------------------------------------------------------------------- Roland57 · 2023-04-08 21:47 @ozznixon I don't exactly what you try to do, but maybe you could take a look to this project. It's a graphical chess program, a standard Lazarus application, which can also be used from a terminal or, in fact, from an external GUI (XBoard or WinBoard). There is a thread to read standard input. When it is compiled with -dXBOARD, the forms are created but are not visible. The program writes to standard output with a simple WriteLn. ---------------------------------------------------------------------- alpine · 2023-04-08 21:56 @ozznixon File -> New -> Project -> Application and then add {$apptype console} to the project1.lpr: 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 Project1; {$mode objfpc}{$H+}{$apptype console} // <-- hereuses   ... ---------------------------------------------------------------------- ASBzone · 2023-04-11 21:36 Quote from: alpine on April 08, 2023, 11:56:18 pm@ozznixon File -> New -> Project -> Application and then add {$apptype console} to the project1.lpr: That will make it a console app, not a hybrid console/gui app. ---------------------------------------------------------------------- nouzi · 2023-04-11 23:23 See this blog http://kriscode.blogspot.com/2018/02/console-vs-gui-application-in- op.html?m=1 ---------------------------------------------------------------------- alpine · 2023-04-12 08:04 @ASBzone I don't know what complications or side effects that may result, but ... it actually works (to my surprise too). You can use ReadLn/WriteLn in your TForm1 methods. You can try it. Lazarus 2.2.2 (rev lazarus_2_2_2) FPC 3.2.2 i386-win32-win32/win64 ---------------------------------------------------------------------- ccrause · 2023-04-17 08:36 A bit late, but I happened to stumble across a post about Console vs GUI application in Object Pascal - is it either-or? that delves into this topic.  Well worth a read in my opinion. ---------------------------------------------------------------------- alpine · 2023-04-18 08:37 QuoteThat will make it a console app, not a hybrid console/gui app. What I can see into FPC compiler sources is when you put {$apptype console} the image will be marked into the header: 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 peoptheader.Subsystem:=3 which means the console will be automatically allocated by the system. The startup code detects its presence with calling GetStdHandle and assigns Input,Output,... accordingly. (procedure SysInitStdIO in \fpcsrc\rtl\win\syswin.inc) That way you don't need to call AllocConsole by yourself. Everything is prepared for you by the OS and the kind people who wrote the FPC RTL. ---------------------------------------------------------------------- geraldholdsworth · 2023-07-14 16:16 I've managed it, just recently: https://forum.lazarus.freepascal.org/index.php/topic,52546.msg485325.h tml#msg485325 Seems to work quite well in Windows, macOS and Linux.