Changeset 66 for branches/Transpascal/UProject.pas
- Timestamp:
- Oct 18, 2010, 10:00:00 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/UProject.pas
r60 r66 6 6 7 7 uses 8 Classes, SysUtils, Contnrs, Dialogs ;8 Classes, SysUtils, Contnrs, Dialogs, DOM, XMLWrite, XMLRead; 9 9 10 10 type … … 15 15 Parent: TProjectNode; 16 16 Name: string; 17 procedure SaveToXMLNode(Node: TDOMNode); virtual; 18 procedure LoadFromXMLNode(Node: TDOMNode); virtual; 17 19 procedure Load; virtual; 18 20 procedure Save; virtual; … … 26 28 constructor Create; 27 29 destructor Destroy; override; 30 procedure SaveToXMLNode(Node: TDOMNode); override; 31 procedure LoadFromXMLNode(Node: TDOMNode); override; 28 32 procedure Load; override; 29 33 procedure Save; override; … … 38 42 procedure Load; override; 39 43 procedure Save; override; 44 procedure SaveToXMLNode(Node: TDOMNode); override; 45 procedure LoadFromXMLNode(Node: TDOMNode); override; 40 46 function SearchFile(FileName: string): TProjectFile; 41 47 end; … … 43 49 TProject = class(TProjectGroup) 44 50 RootDir: string; 51 procedure LoadFromFile(FileName: string); 52 procedure SaveToFile(FileName: string); 45 53 function GetDir(IncludeRoot: Boolean = False): string; override; 54 procedure Load; override; 55 procedure Save; override; 56 procedure SaveToXMLNode(Node: TDOMNode); override; 57 procedure LoadFromXMLNode(Node: TDOMNode); override; 58 procedure Clear; 46 59 end; 47 60 … … 77 90 for I := 0 to Items.Count - 1 do 78 91 TProjectNode(Items[I]).Save; 92 end; 93 94 procedure TProjectGroup.SaveToXMLNode(Node: TDOMNode); 95 begin 96 inherited SaveToXMLNode(Node); 79 97 end; 80 98 … … 111 129 end; 112 130 131 procedure TProjectFile.SaveToXMLNode(Node: TDOMNode); 132 begin 133 inherited SaveToXMLNode(Node); 134 end; 135 136 procedure TProjectFile.LoadFromXMLNode(Node: TDOMNode); 137 begin 138 inherited LoadFromXMLNode(Node); 139 Load; 140 end; 141 113 142 procedure TProjectFile.Load; 114 143 begin … … 125 154 { TProjectNode } 126 155 156 procedure TProjectNode.SaveToXMLNode(Node: TDOMNode); 157 begin 158 159 end; 160 161 procedure TProjectNode.LoadFromXMLNode(Node: TDOMNode); 162 begin 163 Name := UTF8Encode(string(TDOMElement(Node).GetAttribute('Name'))); 164 end; 165 127 166 procedure TProjectNode.Load; 128 167 begin … … 143 182 { TProject } 144 183 184 procedure TProject.LoadFromFile(FileName: string); 185 var 186 Doc: TXMLDocument; 187 NewNode: TDOMNode; 188 NewSubNode: TDOMNode; 189 I: Integer; 190 Text: string; 191 begin 192 try 193 Clear; 194 RootDir := ExtractFileDir(FileName) + '/'; 195 Name := ExtractFileName(FileName); 196 Name := Copy(Name, 1, Length(Name) - Length(ExtractFileExt(FileName))); 197 198 ReadXMLFile(Doc, UTF8Decode(FileName)); 199 200 NewNode := Doc.DocumentElement.FindNode('Files'); 201 if Assigned(NewNode) then 202 LoadFromXMLNode(NewNode); 203 finally 204 Doc.Free; 205 end; 206 end; 207 208 procedure TProjectGroup.LoadFromXMLNode(Node: TDOMNode); 209 var 210 Child: TDOMNode; 211 ProjectNode: TProjectNode; 212 NodeType: string; 213 begin 214 Name := UTF8Encode(TDOMElement(Node).GetAttribute('Name')); 215 Child := Node.FirstChild; 216 while Assigned(Child) do begin 217 NodeType := TDOMElement(Child).GetAttribute('Type'); 218 if NodeType = 'Folder' then 219 ProjectNode := TProjectGroup.Create 220 else if NodeType = 'File' then 221 ProjectNode := TProjectFile.Create 222 else ProjectNode := nil; 223 if Assigned(ProjectNode) then begin 224 ProjectNode.Parent := Self; 225 ProjectNode.LoadFromXMLNode(Child); 226 Items.Add(ProjectNode); 227 end; 228 229 Child := Child.NextSibling; 230 end; 231 end; 232 233 procedure TProject.SaveToFile(FileName: string); 234 begin 235 236 end; 237 145 238 function TProject.GetDir(IncludeRoot: Boolean): string; 146 239 begin … … 148 241 end; 149 242 243 procedure TProject.Load; 244 begin 245 inherited Load; 246 end; 247 248 procedure TProject.Save; 249 begin 250 inherited Save; 251 end; 252 253 procedure TProject.SaveToXMLNode(Node: TDOMNode); 254 begin 255 inherited SaveToXMLNode(Node); 256 end; 257 258 procedure TProject.LoadFromXMLNode(Node: TDOMNode); 259 begin 260 inherited LoadFromXMLNode(Node); 261 end; 262 263 procedure TProject.Clear; 264 begin 265 Items.Clear; 266 end; 267 150 268 end. 151 269
Note:
See TracChangeset
for help on using the changeset viewer.