Changeset 285 for trunk/UNation.pas
- Timestamp:
- Mar 10, 2019, 11:57:03 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UNation.pas
r284 r285 6 6 7 7 uses 8 Classes, SysUtils, fgl,DOM, UXMLUtils, Graphics, UItemList;8 Classes, SysUtils, DOM, UXMLUtils, Graphics, UItemList; 9 9 10 10 type … … 17 17 procedure GetValue(Index: Integer; out Value); override; 18 18 procedure SetValue(Index: Integer; var Value); override; 19 procedure Assign(Source: TItem); override; 20 procedure LoadFromNode(Node: TDOMNode); override; 21 procedure SaveToNode(Node: TDOMNode); override; 19 class function GetClassSysName: string; override; 22 20 end; 23 21 … … 25 23 26 24 TNations = class(TItemList) 27 function GetItemClass: TItemClass; override; 28 procedure LoadFromNode(Node: TDOMNode); 29 procedure SaveToNode(Node: TDOMNode); 30 constructor Create(FreeObjects: Boolean = True); 25 class function GetItemClass: TItemClass; override; 31 26 end; 32 27 … … 44 39 function TNation.GetFields: TItemFields; 45 40 begin 46 inherited; 47 Result.AddField('Name'); 48 Result.AddField('Color'); 41 Result := inherited; 42 Result.AddField(2, 'Color', 'Color', dtColor); 49 43 end; 50 44 51 45 procedure TNation.GetValue(Index: Integer; out Value); 52 46 begin 53 if Index = 0then string(Value) := Name54 else if Index = 1then TColor(Value) := Color47 if Index = 1 then string(Value) := Name 48 else if Index = 2 then TColor(Value) := Color 55 49 else raise Exception.Create('Unsupported value index ' + IntToStr(Index)); 56 50 end; … … 58 52 procedure TNation.SetValue(Index: Integer; var Value); 59 53 begin 60 if Index = 0then Name := string(Value)61 else if Index = 1then Color := TColor(Value)54 if Index = 1 then Name := string(Value) 55 else if Index = 2 then Color := TColor(Value) 62 56 else raise Exception.Create('Unsupported value index ' + IntToStr(Index)); 63 57 end; 64 58 65 procedure TNation.Assign(Source: TItem);59 class function TNation.GetClassSysName: string; 66 60 begin 67 inherited; 68 Color := TNation(Source).Color; 69 end; 70 71 procedure TNation.LoadFromNode(Node: TDOMNode); 72 begin 73 inherited; 74 Color := ReadInteger(Node, 'Color', 0); 75 end; 76 77 procedure TNation.SaveToNode(Node: TDOMNode); 78 begin 79 inherited; 80 WriteInteger(Node, 'Color', Color); 61 Result := 'Nation'; 81 62 end; 82 63 83 64 { TNations } 84 65 85 function TNations.GetItemClass: TItemClass;66 class function TNations.GetItemClass: TItemClass; 86 67 begin 87 68 Result := TNation; 88 69 end; 89 70 90 procedure TNations.LoadFromNode(Node: TDOMNode);91 var92 Node2: TDOMNode;93 NewItem: TNation;94 begin95 Count := 0;96 Node2 := Node.FirstChild;97 while Assigned(Node2) and (Node2.NodeName = 'Nation') do begin98 NewItem := TNation.Create;99 NewItem.LoadFromNode(Node2);100 Add(NewItem);101 Node2 := Node2.NextSibling;102 end;103 end;104 105 procedure TNations.SaveToNode(Node: TDOMNode);106 var107 I: Integer;108 NewNode2: TDOMNode;109 begin110 for I := 0 to Count - 1 do111 with Items[I] do begin112 NewNode2 := Node.OwnerDocument.CreateElement('Nation');113 Node.AppendChild(NewNode2);114 SaveToNode(NewNode2);115 end;116 end;117 118 constructor TNations.Create(FreeObjects: Boolean);119 begin120 inherited;121 end;122 123 71 end. 124 72
Note:
See TracChangeset
for help on using the changeset viewer.