![]() |
Programmparameter auslesen
Liste der Anhänge anzeigen (Anzahl: 3)
Einige kennen das bestimmt, wie schwer sich manchmal die Parameter auswerten lassen,
vorallem wenn die Parameter keine feste Reihenfolge besitzen und wenn man sie mit Namen ansprechen möchte. Über ParamStr und ParamCount hat man ja leider nicht viele Möglichkeiten zur Behandlung der Parameter.
Anzuwenden ist es relativ einfach ... z.B. so
Delphi-Quellcode:
Es gibt 3 Versionen:
with TParameter.Create do
try CommandPrefix := '/'; ValueSeperator := '='; if Exists['file'] then // für /file:"c:\irgendwo\dat.ei" ShowMessage(Value['file']); finally Free; end;
Selber nutze ich die Record-Variante ein, welche man so verwenden klnnte
Delphi-Quellcode:
with TParameter.GetDefault do begin
if Exists['file'] then ShowMessage(Value['file']); ... end;
Delphi-Quellcode:
hier die wichtigsten Header der Record-Variante (die Classen-Varianten sehn ähnlich aus)
var Params: TParameter;
if Params.Exists['file'] then ShowMessage(Params.Value['file']); ...
Delphi-Quellcode:
// possible parameter combinations:
// ... {value} ... // ... -{name} ... // ... -{name}={value} ... // ... -{name}== {value} ... < parameter group // ... -{name}=== {value to end} < parameter group to the end of parameter block // ... "-{value}" ... < escaped command prefix will be ignored // // names and values can be escaped with " // ... "{val ue}" ... // ... -"{na me}" ... // ... -{name}="{val ue}" ... // ... -"{na me}"={value} ... // ... -"{na me}"="{val ue}" ... // ... -"{na me}={val ue}" ... // // default: // CommandLine the command line with which the program was started // CommandPrefix - and / // ValueSeperator = and : // CaseSensitive False // LowerCaseParams False // TrimParams False TParameterProc = Function(Index: Integer; Name, Value, ValueEOP: String): Boolean of Object; TParameter = Record Strict Private ... Public Class Function GetDefault: TParameter; Static; Procedure SetCommandLine(S: String; IncludingApp: Boolean = True); Property Application: String Read GetApp; Function ParamCount: Integer; Property Param [idx: Integer]: String Index 0 Read GetParam; Property ParamLC [idx: Integer]: String Index 1 Read GetParam; Property ParamEOP[idx: Integer]: String Index 2 Read GetParam; Property CommandPrefix: Char Index 0 Read GetChar Write SetChar; // #0 if not used Property ValueSeperator: Char Index 1 Read GetChar Write SetChar; // Property CommandPrefix2: Char Index 2 Read GetChar Write SetChar; // Property ValueSeperator2: Char Index 3 Read GetChar Write SetChar; // Property CaseSensitive: Boolean Index 0 Read GetBool Write SetBool; Property LowerCaseParams: Boolean Index 1 Read GetBool Write SetBool; Property TrimParams: Boolean Index 2 Read GetBool Write SetBool; Property Exists [Name: String]: Boolean Read GetExists; Property Value [Name: String]: Variant Index 0 Read GetValue; Default; Property ValueLC [Name: String]: Variant Index 1 Read GetValue; Property ValueEOP[Name: String]: Variant Index 2 Read GetValue; Function IndexOf (Name: String): Integer; Property Name [idx: Integer]: String Index 3 Read GetParam; Function Parse(Proc: TParameterProc): Integer; // if Proc retunt FALSE then parsing is stopped Function GetModule: String; Function GetModulePath: String; Property GetCall: String Read FCommandLine; End; |
Re: Programmparameter auslesen
So, nochmal zum Großteil überarbeitet.
@Matze: wenn keiner 'nen Fehler entdeckt, dann isses jetzt fertsch :stupid: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:49 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 by Thomas Breitkreuz