Changeset 3 for trunk/UDatabaseXML.pas


Ignore:
Timestamp:
Jan 18, 2015, 5:25:37 PM (10 years ago)
Author:
chronos
Message:
  • Added: Support for editing String and DateTime value types in record edit form.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33MyData.lps
        44data.xml
         5Config.xml
  • trunk/UDatabaseXML.pas

    r2 r3  
    1414  private
    1515    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);
    1620    procedure LoadNodeField(Field: TField; Node: TDOMNode);
    1721    procedure SaveNodeField(Field: TField; Node: TDOMNode);
     
    4549end;
    4650
     51procedure TDatabaseXML.LoadNodeRecord(Row: TRecord; Node: TDOMNode);
     52var
     53  Node2: TDOMNode;
     54  NewValue: TValue;
     55  I: Integer;
     56begin
     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;
     74end;
     75
     76procedure TDatabaseXML.SaveNodeRecord(Row: TRecord; Node: TDOMNode);
     77var
     78  I: Integer;
     79  NewNode: TDOMNode;
     80begin
     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;
     89end;
     90
     91procedure TDatabaseXML.LoadNodeRecords(Records: TRecords; Node: TDOMNode);
     92var
     93  Node2: TDOMNode;
     94  NewRecord: TRecord;
     95begin
     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;
     105end;
     106
     107procedure TDatabaseXML.SaveNodeRecords(Records: TRecords; Node: TDOMNode);
     108var
     109  I: Integer;
     110  NewNode: TDOMNode;
     111begin
     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;
     117end;
     118
    47119procedure TDatabaseXML.LoadNodeField(Field: TField; Node: TDOMNode);
    48120begin
     
    97169  if Assigned(NewNode) then
    98170    LoadNodeFields(Table.Fields, NewNode);
     171
     172  NewNode := Node.FindNode('Records');
     173  if Assigned(NewNode) then
     174    LoadNodeRecords(Table.Records, NewNode);
    99175end;
    100176
     
    108184  Node.AppendChild(NewNode);
    109185  SaveNodeFields(Table.Fields, NewNode);
     186
     187  NewNode := Node.OwnerDocument.CreateElement('Records');
     188  Node.AppendChild(NewNode);
     189  SaveNodeRecords(Table.Records, NewNode);
    110190end;
    111191
     
    164244  RootNode: TDOMNode;
    165245begin
     246  if FileName = '' then exit;
    166247  Doc := TXMLDocument.Create;
    167248  with Doc do try
Note: See TracChangeset for help on using the changeset viewer.