Changeset 64 for trunk/Packages/Common


Ignore:
Timestamp:
Sep 26, 2014, 9:01:50 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Improved saving game state to XML file. Not yet finished and can't be loaded yet.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UXMLUtils.pas

    r43 r64  
    77uses
    88  {$IFDEF WINDOWS}Windows,{$ENDIF}
    9   Classes, SysUtils, DateUtils;
     9  Classes, SysUtils, DateUtils, XMLRead, XMLWrite, DOM;
    1010
    1111function XMLTimeToDateTime(XMLDateTime: string): TDateTime;
    1212function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;
     13procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer);
     14procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean);
     15procedure WriteString(Node: TDOMNode; Name: string; Value: string);
     16function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer;
     17function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean;
     18function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string;
    1319
    1420
     
    123129end;
    124130
     131procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer);
     132var
     133  NewNode: TDOMNode;
     134begin
     135  NewNode := Node.OwnerDocument.CreateElement(Name);
     136  NewNode.TextContent := IntToStr(Value);
     137  Node.AppendChild(NewNode);
     138end;
     139
     140procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean);
     141var
     142  NewNode: TDOMNode;
     143begin
     144  NewNode := Node.OwnerDocument.CreateElement(Name);
     145  NewNode.TextContent := BoolToStr(Value);
     146  Node.AppendChild(NewNode);
     147end;
     148
     149procedure WriteString(Node: TDOMNode; Name: string; Value: string);
     150var
     151  NewNode: TDOMNode;
     152begin
     153  NewNode := Node.OwnerDocument.CreateElement(Name);
     154  NewNode.TextContent := Value;
     155  Node.AppendChild(NewNode);
     156end;
     157
     158function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer;
     159var
     160  NewNode: TDOMNode;
     161begin
     162  Result := DefaultValue;
     163  NewNode := Node.FindNode(Name);
     164  if Assigned(NewNode) then
     165    Result := StrToInt(NewNode.TextContent);
     166end;
     167
     168function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean;
     169var
     170  NewNode: TDOMNode;
     171begin
     172  Result := DefaultValue;
     173  NewNode := Node.FindNode(Name);
     174  if Assigned(NewNode) then
     175    Result := StrToBool(NewNode.TextContent);
     176end;
     177
     178function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string;
     179var
     180  NewNode: TDOMNode;
     181begin
     182  Result := DefaultValue;
     183  NewNode := Node.FindNode(Name);
     184  if Assigned(NewNode) then
     185    Result := NewNode.TextContent;
     186end;
     187
    125188end.
    126189
Note: See TracChangeset for help on using the changeset viewer.