Changeset 289 for trunk/UBuilding.pas
- Timestamp:
- Mar 24, 2019, 11:15:07 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UBuilding.pas
r265 r289 9 9 10 10 type 11 12 { TBuildingKind } 13 11 14 TBuildingKind = class 12 15 Id: Integer; 13 16 Name: string; 14 17 Cost: Integer; 18 procedure Assign(Source: TBuildingKind); 19 procedure LoadFromNode(Node: TDOMNode); 20 procedure SaveToNode(Node: TDOMNode); 15 21 end; 16 22 … … 19 25 TBuildingKinds = class(TFPGObjectList<TBuildingKind>) 20 26 function AddNew(Name: string): TBuildingKind; 27 procedure LoadFromNode(Node: TDOMNode); 28 procedure SaveToNode(Node: TDOMNode); 29 procedure Assign(Source: TBuildingKinds); 21 30 end; 22 31 … … 25 34 end; 26 35 36 resourcestring 37 SBuilding = 'Building'; 38 27 39 28 40 implementation 41 42 { TBuildingKind } 43 44 procedure TBuildingKind.Assign(Source: TBuildingKind); 45 begin 46 Name := Source.Name; 47 Cost := Source.Cost; 48 end; 49 50 procedure TBuildingKind.LoadFromNode(Node: TDOMNode); 51 begin 52 Id := ReadInteger(Node, 'Id', 0); 53 Name := ReadString(Node, 'Name', ''); 54 Cost := ReadInteger(Node, 'Cost', 0); 55 end; 56 57 procedure TBuildingKind.SaveToNode(Node: TDOMNode); 58 begin 59 WriteInteger(Node, 'Id', Id); 60 WriteString(Node, 'Name', Name); 61 WriteInteger(Node, 'Cost', Cost); 62 end; 29 63 30 64 { TBuildingKinds } … … 37 71 end; 38 72 73 procedure TBuildingKinds.LoadFromNode(Node: TDOMNode); 74 var 75 Node2: TDOMNode; 76 NewItem: TBuildingKind; 77 begin 78 Count := 0; 79 Node2 := Node.FirstChild; 80 while Assigned(Node2) and (Node2.NodeName = 'BuildingKind') do begin 81 NewItem := TBuildingKind.Create; 82 NewItem.LoadFromNode(Node2); 83 Add(NewItem); 84 Node2 := Node2.NextSibling; 85 end; 86 end; 87 88 procedure TBuildingKinds.SaveToNode(Node: TDOMNode); 89 var 90 I: Integer; 91 NewNode2: TDOMNode; 92 begin 93 for I := 0 to Count - 1 do 94 with Items[I] do begin 95 NewNode2 := Node.OwnerDocument.CreateElement('BuildingKind'); 96 Node.AppendChild(NewNode2); 97 SaveToNode(NewNode2); 98 end; 99 end; 100 101 procedure TBuildingKinds.Assign(Source: TBuildingKinds); 102 var 103 I: Integer; 104 begin 105 while Count > Source.Count do Delete(Count - 1); 106 while Count < Source.Count do AddNew(''); 107 for I := 0 to Count - 1 do 108 Items[I].Assign(Source.Items[I]); 109 end; 110 39 111 end. 40 112
Note:
See TracChangeset
for help on using the changeset viewer.