-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
CloudAPI.Parameter.pas
68 lines (57 loc) · 1.75 KB
/
CloudAPI.Parameter.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
unit CloudAPI.Parameter;
interface
uses
CloudAPI.Types,
System.Rtti;
type
TcaParameter = record
private
FName: string;
FValue: TValue;
FParameterType: TcaParameterType;
FIsRequired: Boolean;
FDefaultValue: TValue;
public
function ValueAsString: string;
function DefaultValueAsString: string;
function IsDefaultParameter: Boolean;
class function Create(const AName: string; const AValue, ADefaultValue: TValue;
const AParameterType: TcaParameterType; AIsRequired: Boolean): TcaParameter; static;
public
property Name: string read FName write FName;
property Value: TValue read FValue write FValue;
property DefaultValue: TValue read FDefaultValue write FDefaultValue;
property ParameterType: TcaParameterType read FParameterType write FParameterType;
property IsRequired: Boolean read FIsRequired write FIsRequired;
end;
implementation
uses
CloudAPI.RequestArgument;
{ TcaParameter }
class function TcaParameter.Create(const AName: string; const AValue, ADefaultValue: TValue;
const AParameterType: TcaParameterType; AIsRequired: Boolean): TcaParameter;
begin
Result.Name := AName;
Result.Value := AValue;
Result.DefaultValue := ADefaultValue;
Result.ParameterType := AParameterType;
Result.IsRequired := AIsRequired;
end;
function TcaParameter.DefaultValueAsString: string;
begin
if not TcaRequestArgument.Current.TryConvertToString(DefaultValue, Result) then
Result := '';
end;
function TcaParameter.IsDefaultParameter: Boolean;
var
LVal, LDefVal: string;
begin
LVal := ValueAsString;
LDefVal := DefaultValueAsString;
Result := LVal = LDefVal;
end;
function TcaParameter.ValueAsString: string;
begin
Result := TcaRequestArgument.Current.ConvertToString(Value);
end;
end.