Catalog · How the catalog works
ParamParser
Minimal Delphi/Object pascal application execution parameters parser
- ★ 1 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
ParamParser
A minimal command-line parameter parser for Delphi / Object Pascal applications.
Features
- 🪶 One file, no dependencies. It only needs
Classes,SysUtilsandMath. - 🏳️ Flags:
-dor--debugreturn'true'. - 🧩 Valued parameters:
-t valueor--target valuereturn'value'. - 🔀 Short and long names: look up
-tand--targetin one call. - 🎯 Exact matching:
-tdoes not match--test, and it does not match a value that contains-t.
Installation
- Copy
paramparser.pasinto your project folder, or add its folder to your unit search path. - Add
ParamParserto yourusesclause.
[!NOTE] The unit does not declare a compiler mode. With Free Pascal / Lazarus, compile it in
objfpcordelphimode, either from the project options or with-Mobjfpcon the command line, so thatResultis available.
Quick start
program Demo;
{$mode objfpc}{$H+}
uses
Classes, ParamParser;
var
Params: TStringList;
begin
Params := TStringList.Create;
try
ParseParams(Params);
WriteLn('Target: ', GetParam(Params, 't', 'target'));
WriteLn('Debug: ', GetParam(Params, 'd', 'debug'));
finally
Params.Free;
end;
end.$ ./demo -t production --debug
Target: production
Debug: true
$ ./demo --target staging
Target: staging
Debug: falseAPI
ParseParams
procedure ParseParams(var ParamList: TStringList);Reads the parameters passed to the program (ParamStr(1) to ParamStr(ParamCount)) and adds them to ParamList.
- A parameter that starts with
-or--and is followed by a parameter that does not start with-is stored with its value, as-t|value. - Any other parameter that starts with
-or--is stored as a flag, as-d. - Parameters that do not start with
-and do not follow a parameter name are ignored.
[!IMPORTANT] The caller creates
ParamListbefore the call and frees it afterwards.
GetParam
function GetParam(var ParamList: TStringList; ParamName: String;
LongParamName: String): String;Looks up a parameter by its short name (-ParamName) or its long name (--LongParamName). Pass the names without the dashes.
| Command line | GetParam(Params, 't', 'target') |
|---|---|
-t production |
'production' |
--target production |
'production' |
-t |
'true' |
| (not passed) | 'false' |
The result is always a String. Convert it as needed, for example with StrToBool or StrToIntDef.
Behavior and limitations
- A value cannot start with
-. In-n -5,-5is read as another parameter, so-nbecomes a flag. - Combined short flags such as
-abcare not split.-abcis a single parameter namedabc. - The
--name=valuesyntax is not supported. Use--name value. - Names are case-sensitive:
-Tand-tare different parameters. - If a parameter is passed more than once,
GetParamreturns the first one.
License
Distributed under the MIT License. © 2025 Rodrigo Peetz.

