Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6109837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:26:56+00:00 2026-05-23T14:26:56+00:00

How could I create a Console Application that could work with or without a

  • 0

How could I create a Console Application that could work with or without a GUI?

For example, say if I had a console application, If i tried launching this console app from Windows Explorer it will not work it will just close, but I could call it from my GUI Application or the Windows Command Console (cmd.exe) and pass some switches (parameters?) to it.

That way some useful functions can be used without even starting the GUI Application, they can be called from the command line.

EDIT

I am not sure how to create the Console Application, especially that would accept flags (switches, parameters?).

I have seen some Applications that do something similar. For example they might have a Console Application that will convert a bmp to a png, and the GUI calls this Console Application and passes the arguments etc to it.

Hope that makes sense.

So how could I employ something like this?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:26:56+00:00Added an answer on May 23, 2026 at 2:26 pm

    For example, say if I had a console application, If i tried launching this console app from Windows Explorer it will not work it will just close, but I could call it from my GUI Application or the Windows Command Console (cmd.exe) and pass some switches (parameters?) to it.

    It will work. However, the console window will disappear as soon as your program has exited. If you want to give the user a chance to read the output of your console application before the window is closed, simply end your program with a single

    Readln;
    

    or

    Writeln('Press Enter to exit.');
    Readln;
    

    If you want to use a console window for output (or input) in a GUI application, you can give the AllocConsole and FreeConsole functions a try.

    Command-line arguments (such as myapp.exe /OPEN "C:\some dir\file.txt" /THENEXIT) can be used in all types of Windows applications, both GUI apps and console apps. Just use the ParamCount and ParamStr functions.

    How to Create a Console Application that Accepts Command-Line Arguments

    In the Delphi IDE, choose File/New/Console Application. Then write

    program Project1;
    
    {$APPTYPE CONSOLE}
    
    uses
      Windows, SysUtils;
    
    var
      freq: integer;
    
    begin
    
      if ParamCount = 0 then
        Writeln('No arguments passed.')
    
      else if ParamCount >= 1 then
    
        if SameText(ParamStr(1), '/msg') then
        begin
    
            if ParamCount = 1 then
              Writeln('No message to display!')
            else
              MessageBox(0, PChar(ParamStr(2)), 'My Console Application',
                MB_ICONINFORMATION);
    
        end
    
        else if SameText(ParamStr(1), '/beep') then
        begin
    
          freq := 400;
    
          if ParamCount >= 2 then
            if not TryStrToInt(ParamStr(2), freq) then
              Writeln('Invalid frequency: ', ParamStr(2));
    
          Windows.Beep(freq, 2000);
    
        end;
    
    
    end.
    

    Compile the program. Then open a command processor (CMD.EXE) and go to the directory where Project1.exe is.

    Then try

    C:\Users\Andreas Rejbrand\Documents\RAD Studio\Projects>project1
    No arguments passed.
    
    C:\Users\Andreas Rejbrand\Documents\RAD Studio\Projects>project1 /msg
    No message to display!
    
    C:\Users\Andreas Rejbrand\Documents\RAD Studio\Projects>project1 /msg "This is a test."
    
    C:\Users\Andreas Rejbrand\Documents\RAD Studio\Projects>project1 /beep
    
    C:\Users\Andreas Rejbrand\Documents\RAD Studio\Projects>project1 /beep 600
    
    C:\Users\Andreas Rejbrand\Documents\RAD Studio\Projects>
    

    How to pass three arguments

    if ParamCount >= 1 then
    begin
    
      if SameText(ParamStr(1), '/CONVERT') then
      begin
    
        // The user wants to convert
    
        if ParamCount <= 2 then
        begin
          Writeln('Too few arguments!');
          Exit;
        end;
    
        FileName1 := ParamStr(2);
        FileName2 := ParamStr(3);
    
        DoConvert(FileName1, FileName2);
    
      end;
    
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have a Flash website where you could create an avatar
I need to create a console application that has a main() function and pop
I have a reference application that I use to work through DDD issues, and
I have a basic C# console application that I would like to run as
Obviously I could create a Calendar object with the date and use get(DAY) on
I remember back when I used to do C++ Builder apps, you could create
Years ago when I was working with C# I could easily create a temporary
We get the following error; The request was aborted: Could not create SSL/TLS secure
I know I could write scripts and create jobs to run them, but at
Could anyone could point me to some code/give me ideas on how to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.