You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Returns True if parameter exists or has default value
67
+
// For non-boolean parameters, returns True when a value or default exists
68
68
if GetParameterValue('--param-name', StrValue) then
69
69
// Use StrValue...
70
70
71
-
// Framework automatically converts to correct type
72
-
GetParameterValue('--count', IntValue);
73
-
GetParameterValue('--rate', FloatValue);
74
-
GetParameterValue('--verbose', BoolValue);
71
+
// Retrieve text, then convert explicitly
72
+
if GetParameterValue('--count', IntValueStr) then
73
+
TryStrToInt(IntValueStr, IntValue);
74
+
75
+
if GetParameterValue('--rate', FloatValueStr) then
76
+
TryStrToFloat(FloatValueStr, FloatValue);
77
+
78
+
GetParameterValue('--verbose', BoolValueStr);
79
+
BoolValue := SameText(BoolValueStr, 'true');
75
80
end;
76
81
```
77
82
@@ -752,21 +757,20 @@ To retrieve parameter values in your command's Execute method:
752
757
```pascal
753
758
function TMyCommand.Execute: Integer;
754
759
var
755
-
Name: string;
760
+
Name, CountStr, RateStr, Level: string;
756
761
Count: Integer;
757
762
Rate: Double;
758
-
Level: string;
759
763
begin
760
764
// Get parameter values with error checking
761
765
if GetParameterValue('--name', Name) then
762
766
WriteLn('Name: ', Name);
763
-
764
-
if GetParameterValue('--count', Count) then
767
+
768
+
if GetParameterValue('--count', CountStr) and TryStrToInt(CountStr, Count) then
765
769
WriteLn('Count: ', Count);
766
-
767
-
if GetParameterValue('--rate', Rate) then
770
+
771
+
if GetParameterValue('--rate', RateStr) and TryStrToFloat(RateStr, Rate) then
768
772
WriteLn('Rate: ', Rate:0:2);
769
-
773
+
770
774
if GetParameterValue('--level', Level) then
771
775
WriteLn('Level: ', Level);
772
776
@@ -776,14 +780,24 @@ end;
776
780
777
781
### Best Practices
778
782
779
-
1.**Always Check Return Value**: The `GetParameterValue`function returns `False` if the parameter wasn't provided and has no default value.
783
+
1.**Always Check Return Value**: `GetParameterValue` returns `True` for non-boolean parameters when a value or default exists. Boolean parameters still write to the output string, but return `True` only when the flag/value was explicitly provided.
780
784
781
-
2.**Use Strong Typing**: The framework will automatically convert parameter values to the correct type:
785
+
2.**Convert Retrieved Strings Explicitly**: `GetParameterValue` returns strings, so use `SysUtils` helpers after reading the value:
782
786
```pascal
783
787
var
784
-
Count: Integer;
785
-
Rate: Double;
786
-
IsEnabled: Boolean;
788
+
CountValue, RateValue, EnabledValue: string;
789
+
Count: Integer;
790
+
Rate: Double;
791
+
IsEnabled: Boolean;
792
+
793
+
GetParameterValue('--count', CountValue);
794
+
TryStrToInt(CountValue, Count);
795
+
796
+
GetParameterValue('--rate', RateValue);
797
+
TryStrToFloat(RateValue, Rate);
798
+
799
+
GetParameterValue('--enabled', EnabledValue);
800
+
IsEnabled := SameText(EnabledValue, 'true');
787
801
```
788
802
789
803
3.**Provide Clear Descriptions**: Parameter descriptions appear in help text:
0 commit comments