Changeset 55 for branches/DelphiToC/UProject.pas
- Timestamp:
- Aug 10, 2010, 1:48:38 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/UProject.pas
r54 r55 6 6 7 7 uses 8 Classes, SysUtils, Contnrs ;8 Classes, SysUtils, Contnrs, Dialogs; 9 9 10 10 type … … 13 13 14 14 TProjectNode = class 15 Parent: TProjectNode; 15 16 Name: string; 16 17 procedure Load; virtual; 17 18 procedure Save; virtual; 19 function GetDir(IncludeRoot: Boolean = False): string; virtual; 20 end; 21 22 { TProjectFile } 23 24 TProjectFile = class(TProjectNode) 25 Source: TStringList; 26 ProducedCode: TStringList; 27 constructor Create; 28 destructor Destroy; override; 29 procedure Load; override; 30 procedure Save; override; 18 31 end; 19 32 … … 26 39 procedure Load; override; 27 40 procedure Save; override; 28 end; 29 30 { TProjectFile } 31 32 TProjectFile = class(TProjectNode) 33 Source: TStringList; 34 ProducedCode: TStringList; 35 FileName: string; 36 constructor Create; 37 destructor Destroy; override; 38 procedure Load; override; 39 procedure Save; override; 41 function SearchFile(FileName: string): TProjectFile; 40 42 end; 41 43 42 44 TProject = class(TProjectGroup) 45 RootDir: string; 46 function GetDir(IncludeRoot: Boolean = False): string; override; 43 47 end; 44 48 … … 76 80 end; 77 81 82 function TProjectGroup.SearchFile(FileName: string): TProjectFile; 83 var 84 NamePart: string; 85 I: Integer; 86 begin 87 if Pos('/', FileName) > 0 then 88 NamePart := Copy(FileName, 1, Pos('/', FileName)) 89 else NamePart := FileName; 90 I := 0; 91 while (I < Items.Count) and (TProjectNode(Items[I]).Name <> NamePart) do Inc(I); 92 if I < Items.Count then begin 93 if TProjectNode(Items[I]) is TProjectFile then Result := TProjectFile(Items[I]) 94 else begin 95 Delete(FileName, 1, Length(FileName) + 1); 96 TProjectGroup(Items[I]).SearchFile(FileName); 97 end; 98 end else Result := nil; 99 end; 100 78 101 { TProjectFile } 79 102 … … 94 117 begin 95 118 inherited Load; 96 Source.LoadFromFile( FileName);119 Source.LoadFromFile(Parent.GetDir(True) + Name); 97 120 end; 98 121 … … 100 123 begin 101 124 inherited Save; 102 Source.SaveToFile( FileName);125 Source.SaveToFile(Parent.GetDir(True) + Name); 103 126 end; 104 127 … … 115 138 end; 116 139 140 function TProjectNode.GetDir(IncludeRoot: Boolean = False): string; 141 begin 142 if Assigned(Parent) then Result := Parent.GetDir(IncludeRoot) + Name + '/' 143 else Result := Name + '/'; 144 end; 145 146 { TProject } 147 148 function TProject.GetDir(IncludeRoot: Boolean): string; 149 begin 150 if IncludeRoot then Result := RootDir else Result := ''; 151 end; 152 117 153 end. 118 154
Note:
See TracChangeset
for help on using the changeset viewer.