Changeset 4 for trunk/UDatabaseXML.pas


Ignore:
Timestamp:
Jan 18, 2015, 11:29:26 PM (9 years ago)
Author:
chronos
Message:
  • Moved: Field and value data type declaration moved to separate unit.
  • Modified: Fields edit form is now modal and made need changes need to be accepted.
  • Added: 32x32 icons to actions.
  • Fixed: If fileds count or type changed then table values are updated.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UDatabaseXML.pas

    r3 r4  
    3737implementation
    3838
     39uses
     40  UDataTypes;
     41
    3942resourcestring
    4043  SWrongFileFormat = 'Wrong file format';
     
    5255var
    5356  Node2: TDOMNode;
    54   NewValue: TValue;
    55   I: Integer;
    56 begin
    57   Row.Values.Count := 0;
     57  I: Integer;
     58begin
     59  Row.Values.Count := Row.Parent.Fields.Count;
     60  for I := 0 to Row.Values.Count - 1 do
     61    Row.Values[I] := TValueClass(TField(Row.Parent.Fields[I]).GetValueClass).Create;
     62
    5863  Node2 := Node.FirstChild;
    5964  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);
     65  while Assigned(Node2) and (Node2.NodeName = 'Value') and (I < Row.Values.Count) do begin
     66    case TField(Row.Parent.Fields[I]).FieldType of
     67      ftString: TValueString(Row.Values[I]).Value := Node2.TextContent;
     68      ftInteger: TValueInteger(Row.Values[I]).Value := StrToInt(Node2.TextContent);
     69      ftDateTime: if Node2.TextContent <> '' then
     70        TValueDateTime(Row.Values[I]).Value := XMLTimeToDateTime(Node2.TextContent);
     71      ftBoolean: TValueBoolean(Row.Values[I]).Value := StrToBool(Node2.TextContent);
     72    end;
    7173    Node2 := Node2.NextSibling;
    7274    Inc(I);
     
    8284    NewNode := Node.OwnerDocument.CreateElement('Value');
    8385    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);
     86    case TField(Row.Parent.Fields[I]).FieldType of
     87      ftString: NewNode.TextContent := TValueString(Row.Values[I]).Value;
     88      ftInteger: NewNode.TextContent := IntToStr(TValueInteger(Row.Values[I]).Value);
     89      ftDateTime: NewNode.TextContent := DateTimeToXMLTime(TValueDateTime(Row.Values[I]).Value);
     90      ftBoolean: NewNode.TextContent := BoolToStr(TValueBoolean(Row.Values[I]).Value);
     91      ftFloat: NewNode.TextContent := FloatToStr(TValueFloat(Row.Values[I]).Value);
     92    end;
    8893  end;
    8994end;
     
    165170begin
    166171  Table.Name := ReadString(Node, 'Name', '');
     172  Table.Caption := ReadString(Node, 'Caption', '');
    167173
    168174  NewNode := Node.FindNode('Fields');
     
    180186begin
    181187  WriteString(Node, 'Name', Table.Name);
     188  WriteString(Node, 'Caption', Table.Caption);
    182189
    183190  NewNode := Node.OwnerDocument.CreateElement('Fields');
Note: See TracChangeset for help on using the changeset viewer.