Changeset 122 for trunk/Packages/Common/UXMLUtils.pas
- Timestamp:
- Jun 29, 2018, 11:44:07 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UXMLUtils.pas
r89 r122 7 7 uses 8 8 {$IFDEF WINDOWS}Windows,{$ENDIF} 9 Classes, SysUtils, DateUtils ;9 Classes, SysUtils, DateUtils, DOM; 10 10 11 11 function XMLTimeToDateTime(XMLDateTime: string): TDateTime; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 13 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 14 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); 15 procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean); 16 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 17 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 18 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 19 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; 20 function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean; 21 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 22 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime; 13 23 14 24 … … 20 30 TimeZoneInfo: TTimeZoneInformation; 21 31 begin 32 {$push}{$warn 5057 off} 22 33 case GetTimeZoneInformation(TimeZoneInfo) of 23 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;24 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;34 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias; 35 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias; 25 36 else 26 37 Result := 0; 27 38 end; 39 {$pop} 28 40 end; 29 41 {$ELSE} … … 35 47 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 36 48 var 37 I , J: Integer;49 I: Integer; 38 50 Matched: Boolean; 39 51 begin … … 66 78 Minute: Integer; 67 79 Second: Integer; 80 SecondFraction: Double; 68 81 Millisecond: Integer; 69 82 begin … … 88 101 if Pos('Z', XMLDateTime) > 0 then 89 102 LeftCutString(XMLDateTime, Part, 'Z'); 90 Millisecond := StrToInt(Part); 103 SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part); 104 Millisecond := Trunc(SecondFraction * 1000); 91 105 end else begin 92 106 if Pos('+', XMLDateTime) > 0 then … … 106 120 end; 107 121 108 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;122 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 109 123 const 110 124 Neg: array[Boolean] of string = ('+', '-'); … … 123 137 end; 124 138 139 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 140 var 141 NewNode: TDOMNode; 142 begin 143 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 144 NewNode.TextContent := DOMString(IntToStr(Value)); 145 Node.AppendChild(NewNode); 146 end; 147 148 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); 149 var 150 NewNode: TDOMNode; 151 begin 152 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 153 NewNode.TextContent := DOMString(IntToStr(Value)); 154 Node.AppendChild(NewNode); 155 end; 156 157 procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean); 158 var 159 NewNode: TDOMNode; 160 begin 161 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 162 NewNode.TextContent := DOMString(BoolToStr(Value)); 163 Node.AppendChild(NewNode); 164 end; 165 166 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 167 var 168 NewNode: TDOMNode; 169 begin 170 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 171 NewNode.TextContent := DOMString(Value); 172 Node.AppendChild(NewNode); 173 end; 174 175 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 176 var 177 NewNode: TDOMNode; 178 begin 179 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 180 NewNode.TextContent := DOMString(DateTimeToXMLTime(Value)); 181 Node.AppendChild(NewNode); 182 end; 183 184 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 185 var 186 NewNode: TDOMNode; 187 begin 188 Result := DefaultValue; 189 NewNode := Node.FindNode(DOMString(Name)); 190 if Assigned(NewNode) then 191 Result := StrToInt(string(NewNode.TextContent)); 192 end; 193 194 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; 195 var 196 NewNode: TDOMNode; 197 begin 198 Result := DefaultValue; 199 NewNode := Node.FindNode(DOMString(Name)); 200 if Assigned(NewNode) then 201 Result := StrToInt64(string(NewNode.TextContent)); 202 end; 203 204 function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean; 205 var 206 NewNode: TDOMNode; 207 begin 208 Result := DefaultValue; 209 NewNode := Node.FindNode(DOMString(Name)); 210 if Assigned(NewNode) then 211 Result := StrToBool(string(NewNode.TextContent)); 212 end; 213 214 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 215 var 216 NewNode: TDOMNode; 217 begin 218 Result := DefaultValue; 219 NewNode := Node.FindNode(DOMString(Name)); 220 if Assigned(NewNode) then 221 Result := string(NewNode.TextContent); 222 end; 223 224 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime 225 ): TDateTime; 226 var 227 NewNode: TDOMNode; 228 begin 229 Result := DefaultValue; 230 NewNode := Node.FindNode(DOMString(Name)); 231 if Assigned(NewNode) then 232 Result := XMLTimeToDateTime(string(NewNode.TextContent)); 233 end; 234 125 235 end. 126 236
Note:
See TracChangeset
for help on using the changeset viewer.