Delphi/Lazarus: Command Line Parameter Tutorial Part 1: Sending
Tutorial by Stefan Trost | Last update on 2023-01-27 | Created on 2012-11-24
In this little tutorial, I want to show you, how you can pass commands or parameters from the command line or via batch files to your Delphi or Lazarus application, to then evaluate these commands or parameters in your program.
In this first part, we will first look at how to send parameters to the program, in the second part, we will see, how to receive and process the parameters.
Command Line
If you call the program from the command line, you can simply pass the parameters after the call of the program, for example:
C:\Delphi>MyApplication.exe param1 param2
With this call we pass two parameters to the program "MyApplication.exe". The first parameter consists of the text "param1", the second parameter of the text "param2". Parameters are separated with spaces. If a parameter should contain spaces itself, we have to write the parameter in quotation marks, such as "param 1".
Batch Script
It is also very simple, if you use a batch file or any other type of script to invoke your program. In this case, you can simply write the parameters like in the command line behind the program file:
@echo off start /wait MyApplication.exe param1 param2
With this method you can also create different BAT files for the different parameter constellations for testing or calling the same program with different settings.
Delphi IDE
To start the program directly from the Delphi IDE with parameters, you can go in the menu to "Run > Parameters". Here, you can enter the parameters, with which the program is started directly after compiling from Delphi. Just type "param1 param2" in the field to pass "param1" and "param2" through the IDE.
Of course, this call directly using the IDE is very useful in the development phase, because that way, you do not always have to start the program after compiling from the command line to try it out. Of course, the data passed through the IDE parameters remain independent of the program itself, they will not be compiled into the program.
Lazarus IDE
Also if we work with Lazarus, we can store parameters in the IDE with which our program is started out of the IDE after compiling. The settings for this can be found in the menu "Run > Run Parameters > Command Line Parameters". In this dialog you will also find some other settings for parameters and environmental variables with which the program should be executed and you can define different modes with which you can save and call up frequently used parameter constellations.
Part 2: Receive parameters
In the second part of the command line tutorial, we will look at how to receive and process the parameters from the command line in the program.
About the Author
You can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile
Related Topics
Windows Batch Script: Computer Shutdown
Tutorial | 2 Comments
Delphi/Lazarus: Command Line Parameter Tutorial Part 2: Receiving
Tutorial | 0 Comments
Put Windows via Script into Hibernation or Sleep Mode
Tutorial | 0 Comments
Repair Text Files with mixed Line Breaks
Tutorial | 0 Comments
MySQL: Line Breaks in MySQL
Tip | 0 Comments
Rewrite Text Files with a fixed Line Length
Tutorial | 0 Comments
How to Replace multiple Texts at the same Time
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.