AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

unit für command line parameter

Ein Thema von freimatz · begonnen am 17. Okt 2019 · letzter Beitrag vom 18. Okt 2019
 
Der schöne Günther

Registriert seit: 6. Mär 2013
6.199 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: unit für command line parameter

  Alt 17. Okt 2019, 09:53
Wobei - Und das ist nur mein persönlicher Geschmack - ich denke dass man so etwas schneller selbst gebaut und auf seine eigenen Bedürfnisse zugeschnitten hat als sich in eine neue Library eingearbeitet, Lizenztexte gelesen und verstanden hat und und und.

Delphi-Quellcode:
program Project9;

{$APPTYPE CONSOLE}
{$R *.res}

uses System.SysUtils;

type
   TCommandLineArgs = record
      isVerbose:   Boolean;
      inputPath:   String;
      outputPath:   String;

      function ToString(): String; inline;
   end;

function getCommandLineArgs(const commandLine: String): TCommandLineArgs;
begin
   Result.isVerbose := FindCmdLineSwitch('isVerbose');
   if not FindCmdLineSwitch('inputPath', Result.inputPath) then
      Result.inputPath := String.Empty;
   if not FindCmdLineSwitch('outputPath', Result.outputPath) then
      Result.outputPath := String.Empty;
end;

{ TCommandLineArgs }

function TCommandLineArgs.ToString(): String;
begin
   Result :=
      String.Format('isVerbose: %d', [isVerbose.ToInteger()])
      + sLineBreak + String.Format('inputPath: "%s"', [inputPath])
      + sLineBreak + String.Format('outputPath: "%s"', [outputPath]);
end;

begin
   WriteLn( getCommandLineArgs(CmdLine).ToString() );
end.
ergibt

Code:
isVerbose: 1
inputPath: ""
outputPath: "C:\users\public\someFile.dat"
bei einem Aufruf mit
Code:
/isVerbose /outputpath:C:\users\public\someFile.dat
Für nicht allzu komplizierte Fälle reicht so etwas doch schon aus?
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz