Changeset 3 for trunk/UDatabaseXML.pas
- Timestamp:
- Jan 18, 2015, 5:25:37 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 3 3 MyData.lps 4 4 data.xml 5 Config.xml
-
- Property svn:ignore
-
trunk/UDatabaseXML.pas
r2 r3 14 14 private 15 15 function GetFileName: string; 16 procedure LoadNodeRecord(Row: TRecord; Node: TDOMNode); 17 procedure SaveNodeRecord(Row: TRecord; Node: TDOMNode); 18 procedure LoadNodeRecords(Records: TRecords; Node: TDOMNode); 19 procedure SaveNodeRecords(Records: TRecords; Node: TDOMNode); 16 20 procedure LoadNodeField(Field: TField; Node: TDOMNode); 17 21 procedure SaveNodeField(Field: TField; Node: TDOMNode); … … 45 49 end; 46 50 51 procedure TDatabaseXML.LoadNodeRecord(Row: TRecord; Node: TDOMNode); 52 var 53 Node2: TDOMNode; 54 NewValue: TValue; 55 I: Integer; 56 begin 57 Row.Values.Count := 0; 58 Node2 := Node.FirstChild; 59 I := 0; 60 while Assigned(Node2) and (Node2.NodeName = 'Value') do begin 61 if TField(Row.Parent.Fields[I]).FieldType = ftString then begin 62 NewValue := TValueString.Create; 63 TValueString(NewValue).Value := Node2.TextContent; 64 end else 65 if TField(Row.Parent.Fields[I]).FieldType = ftDateTime then begin 66 NewValue := TValueDateTime.Create; 67 if Node2.TextContent <> '' then 68 TValueDateTime(NewValue).Value := XMLTimeToDateTime(Node2.TextContent); 69 end else NewValue := TValue.Create; 70 Row.Values.Add(NewValue); 71 Node2 := Node2.NextSibling; 72 Inc(I); 73 end; 74 end; 75 76 procedure TDatabaseXML.SaveNodeRecord(Row: TRecord; Node: TDOMNode); 77 var 78 I: Integer; 79 NewNode: TDOMNode; 80 begin 81 for I := 0 to Row.Values.Count - 1 do begin; 82 NewNode := Node.OwnerDocument.CreateElement('Value'); 83 Node.AppendChild(NewNode); 84 if TField(Row.Parent.Fields[I]).FieldType = ftString then 85 NewNode.TextContent := TValueString(Row.Values[I]).Value; 86 if TField(Row.Parent.Fields[I]).FieldType = ftDateTime then 87 NewNode.TextContent := DateTimeToXMLTime(TValueDateTime(Row.Values[I]).Value); 88 end; 89 end; 90 91 procedure TDatabaseXML.LoadNodeRecords(Records: TRecords; Node: TDOMNode); 92 var 93 Node2: TDOMNode; 94 NewRecord: TRecord; 95 begin 96 Records.Count := 0; 97 Node2 := Node.FirstChild; 98 while Assigned(Node2) and (Node2.NodeName = 'Record') do begin 99 NewRecord := TRecord.Create; 100 NewRecord.Parent := Records.Parent; 101 LoadNodeRecord(NewRecord, Node2); 102 Records.Add(NewRecord); 103 Node2 := Node2.NextSibling; 104 end; 105 end; 106 107 procedure TDatabaseXML.SaveNodeRecords(Records: TRecords; Node: TDOMNode); 108 var 109 I: Integer; 110 NewNode: TDOMNode; 111 begin 112 for I := 0 to Records.Count - 1 do begin; 113 NewNode := Node.OwnerDocument.CreateElement('Record'); 114 Node.AppendChild(NewNode); 115 SaveNodeRecord(TRecord(Records.Items[I]), NewNode); 116 end; 117 end; 118 47 119 procedure TDatabaseXML.LoadNodeField(Field: TField; Node: TDOMNode); 48 120 begin … … 97 169 if Assigned(NewNode) then 98 170 LoadNodeFields(Table.Fields, NewNode); 171 172 NewNode := Node.FindNode('Records'); 173 if Assigned(NewNode) then 174 LoadNodeRecords(Table.Records, NewNode); 99 175 end; 100 176 … … 108 184 Node.AppendChild(NewNode); 109 185 SaveNodeFields(Table.Fields, NewNode); 186 187 NewNode := Node.OwnerDocument.CreateElement('Records'); 188 Node.AppendChild(NewNode); 189 SaveNodeRecords(Table.Records, NewNode); 110 190 end; 111 191 … … 164 244 RootNode: TDOMNode; 165 245 begin 246 if FileName = '' then exit; 166 247 Doc := TXMLDocument.Create; 167 248 with Doc do try
Note:
See TracChangeset
for help on using the changeset viewer.