Console application from Visual program lazarus / 61-Beginners ---------------------------------------------------------------------- Jake012345 · 2020-05-21 16:59 Hello! how can I run a console program from Visual application? (I want it just for effect, but 3 procedure have to write in this.) Thanks! ---------------------------------------------------------------------- Bart · 2020-05-21 19:15 Is this what you want https://wiki.lazarus.freepascal.org/Executing_External_Programs? Bart ---------------------------------------------------------------------- Jake012345 · 2020-05-26 13:20 So I have to write separately programs If I want to show console messages? ---------------------------------------------------------------------- rvk · 2020-05-26 13:50 Quote from: Jake012345 on May 26, 2020, 03:20:04 pmSo I have to write separately programs. You asked to run a console program from your visual application, so, yes... that means a separate program which you (or someone else) need to write. Quote from: Jake012345 on May 26, 2020, 03:20:04 pmIf I want to show console messages? You'll need to clarify. What console? On Windows or Linux? You can have multiple consoles on both platforms. So what exactly do you mean. Normally a visual program isn't connected to any console. So if you wan't to show a console from your visual program, you'll first need to create it before you can write to it. Before that... is there any special need for a console? Can't you just do this with a form and a tmemo on it? A very small example. This can be run from a GUI-program and it will create a console. 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 uses windows; function fpAllocConsole: boolean;begin  Result := AllocConsole;  {$ifdef FPC}  if Result then  begin    IsConsole := True;    StdInputHandle  := 0;    StdOutputHandle := 0;    StdErrorHandle  := 0;    SysInitStdIO;  end;  {$endif FPC}end; procedure DoConsole();var s: string;begin fpAllocConsole; writeln('Enter something or Q to Quit') ; repeat    readln(s);    writeln('You typed: ' + s); until uppercase(s)='Q'; FreeConsole;end; ---------------------------------------------------------------------- Jake012345 · 2020-05-26 15:45 And what are the paramters? c:\...\asd.exe -fast For example: I can make to my program a -fast parameter, and if I use it the program can run with more or less funcions? ---------------------------------------------------------------------- lucamar · 2020-05-26 16:16 Quote from: Jake012345 on May 26, 2020, 05:45:37 pmFor example: I can make to my program a -fast parameter, and if I use it the program can run with more or less funcions? Your program will have all the functions programmed into it, whether it uses them or not. If what you want is to be able to load a leaner, though less "powerful", version then you should move the "extra" functionality to a dynamic library which you would then load (or not) depending on the parameters passed. ---------------------------------------------------------------------- Jake012345 · 2020-05-26 18:27 That's what I'm thinking. But how can I do it? ---------------------------------------------------------------------- rvk · 2020-05-26 18:45 Quote from: Jake012345 on May 26, 2020, 08:27:11 pmThat's what I'm thinking. But how can I do it? Can you explain exactly what you want (not just repeat what others suggest). Do you want a small .exe and load a dll (which is difficult for beginners)? Do you want to read out a parameter -fast from your startup commands? Which you can do with If (paramcount > 0) and (paramstr(1) = '-fast') then .... ; Do you want to run an external program (like you asked for in your opening post) and pass a parameter -fast? ---------------------------------------------------------------------- 440bx · 2020-05-26 18:51 Quote from: Jake012345 on May 26, 2020, 08:27:11 pmThat's what I'm thinking. But how can I do it? What @rvk showed in a previous post is the simplest way to go about it.  You can find a complete working example attached to the following post: https://forum.lazarus.freepascal.org/index.php/topic,44828.msg31 5571.html#msg315571 As far as parameters or anything else, the simplest way is to have the GUI portion share (or pass) some of its data to the console part.  Since the console is part of the GUI program, sharing data is done just as if you were dealing with another GUI window in the program. Also, the questions @rvk asked are good ones.  You need to be a little more precise as to what you want to do in order to get more precise help as well. HTH. ---------------------------------------------------------------------- Jake012345 · 2020-05-27 03:13 My idea is that I write only two programs: An Gui-program and a console program the console program doesn't do anything on simple start, but the Gui- program knows the parameter  s and execute it with theese for the necessary messages. ---------------------------------------------------------------------- rvk · 2020-05-27 05:58 Quote from: Jake012345 on May 27, 2020, 05:13:34 amthe console program doesn't do anything on simple start, but the Gui-program knows the parameter  s and execute it with theese for the necessary messages. Then why not use my suggestion from my first post to use allocconsole? You can start your gui program and open a console for messages. ---------------------------------------------------------------------- dbannon · 2020-05-27 07:10 Quote from: Jake012345 on May 27, 2020, 05:13:34 amMy idea is that I write only two programs: An Gui-program and a console program the console program doesn't do anything on simple start, but the Gui- program knows the parameter  s and execute it with theese for the necessary messages. Jake012345, perhaps another way to think about it is to write one program that has at least two units.  The first unit is a console or command line unit.  It starts up first and if it finds the various things (such as command line parameters)  it needs to know to do its job, it goes and does it.  If it does not know what to do, it allows the GUI unit to startup and the user can click buttons and enter information to instruct the program to do its job. In this model, its easier to have most of the working code in the command line unit or units, it makes sense for the GUI, if its started up, to be able to call them.  The way you are thinking, you always have to start up the GUI, the forms must be created etc, before the code in there can be called. Even if we don't need the forms. Someone here on the forum (sorry, cannot remember who, but thanks!) recently pointed out to me that the lpr file can have things like this in it - 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     ....  Application.Initialize;    if ContinueToGUI then begin        Application.CreateForm(TMainForm, MainForm);        Application.CreateForm(TSett, Sett);   .... The ContinueToGUI() function does things like look at command line options and parameters and either triggers the program's purpose or decides to run the GUI. Davo ---------------------------------------------------------------------- Leledumbo · 2020-05-29 00:14 Sounds like you're trying to make a GUI wrapper over a CLI app, but I'm not too sure. Feels like we have a language barrier here. If I'm right, I have at least 3 projects that do so, 1 of them (1st on the list below) have both the CLI and GUI parts written in the same project folder: https://bitbucket.org/leledumbo/erd- maker/src/default/https://bitbucket.org/leledumbo/zita-aj-bridge- gui/src/default/https://bitbucket.org/leledumbo/express/src/default/