-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVariantUtils.pas
More file actions
110 lines (90 loc) · 2.68 KB
/
Copy pathVariantUtils.pas
File metadata and controls
110 lines (90 loc) · 2.68 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
unit VariantUtils;
interface
uses
Variants, VarUtils, SysUtils;
type
TTypeVar = class
public
class function VarToInt(AValue: Variant): Integer;
class function VarToInt64(AValue: Variant): Int64;
class function VarToDouble(AValue: Variant): Double;
class function VarToValue(AValue: Variant; AVarType: TVarType): Variant;
end;
TVariant = record
private
FValue: Variant;
public
class operator Implicit(AValue: Variant): TVariant; overload;
class operator Implicit(AValue: TVariant): Variant; overload;
class operator Implicit(AValue: TVariant): Integer; overload;
class operator Implicit(AValue: TVariant): String; overload;
class operator Implicit(AValue: TVariant): Int64; overload;
class operator Implicit(AValue: TVariant): Double; overload;
class operator Implicit(AValue: TVariant): TDateTime; overload;
end;
implementation
{ TTypeVar }
class function TTypeVar.VarToInt(AValue: Variant): Integer;
var
ATemp: String;
begin
ATemp := VartoStr(AValue);
Result := StrToInt(ATemp);
end;
class function TTypeVar.VarToInt64(AValue: Variant): Int64;
var
ATemp: String;
begin
ATemp := VartoStr(AValue);
Result := StrToInt64(ATemp);
end;
class function TTypeVar.VarToDouble(AValue: Variant): Double;
var
ATemp: String;
begin
ATemp := VartoStr(AValue);
Result := StrToFloat(ATemp);
end;
class function TTypeVar.VarToValue(AValue: Variant; AVarType: TVarType): Variant;
begin
case AVarType of
varEmpty: Result := '';
varNull: Result := AValue;
varInteger: Result := TTypeVar.VarToInt(AValue);
varByte: Result := TTypeVar.VarToInt(AValue);
varInt64: Result := TTypeVar.VarToInt64(AValue);
varString: Result := Variants.VarToStr(AValue);
varDate: Result := Variants.VarToDateTime(AValue);
varDouble: Result := TTypeVar.VarToDouble(AValue);
end;
end;
{ TVariant }
class operator TVariant.Implicit(AValue: TVariant): Integer;
begin
Result := TTypeVar.VarToValue(AValue.FValue, varInteger);
end;
class operator TVariant.Implicit(AValue: TVariant): String;
begin
Result := TTypeVar.VarToValue(AValue.FValue, varString);
end;
class operator TVariant.Implicit(AValue: TVariant): Int64;
begin
Result := TTypeVar.VarToValue(AValue.FValue, varInt64);
end;
class operator TVariant.Implicit(AValue: TVariant): Double;
begin
Result := TTypeVar.VarToValue(AValue.FValue, varDouble);
end;
class operator TVariant.Implicit(AValue: TVariant): TDateTime;
begin
Result := TTypeVar.VarToValue(AValue.FValue, varDate);
end;
class operator TVariant.Implicit(AValue: Variant): TVariant;
begin
Result.FValue := AValue;
end;
class operator TVariant.Implicit(AValue: TVariant): Variant;
begin
Result := AValue.FValue;
end;
end.