Changeset 13 for trunk/UAcronym.pas
- Timestamp:
- Apr 28, 2016, 10:09:02 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UAcronym.pas
r8 r13 9 9 10 10 type 11 TAcronymC ontexts = class;11 TAcronymCategories = class; 12 12 TAcronymMeanings = class; 13 13 … … 33 33 Language: string; 34 34 Acronym: TAcronym; 35 C ontexts: TAcronymContexts;35 Categories: TAcronymCategories; 36 36 Source: TAcronymSource; 37 37 constructor Create; … … 53 53 end; 54 54 55 { TAcronymC ontext}56 57 TAcronymC ontext= class55 { TAcronymCategory } 56 57 TAcronymCategory = class 58 58 Name: string; 59 59 Acronyms: TObjectList; // TObjectList<TAcronym> … … 62 62 end; 63 63 64 { TAcronymContexts } 65 66 TAcronymContexts = class(TObjectList) 67 function SearchByName(Name: string): TAcronymContext; 68 function AddContext(Name: string): TAcronymContext; 69 end; 64 { TAcronymCategories } 65 66 TAcronymCategories = class(TObjectList) 67 function SearchByName(Name: string): TAcronymCategory; 68 function AddContext(Name: string): TAcronymCategory; 69 procedure AssignToStrings(Strings: TStrings); 70 procedure AssignFromStrings(Strings: TStrings); 71 end; 72 73 { TAcronymEntry } 70 74 71 75 TAcronymEntry = class … … 73 77 Meaning: string; 74 78 Description: string; 79 Categories: TStringList; 80 constructor Create; 81 destructor Destroy; override; 75 82 end; 76 83 … … 81 88 Sources: TObjectList; // TObjectList<TAcronymSource> 82 89 Acronyms: TAcronyms; 83 C ontexts: TAcronymContexts;90 Categories: TAcronymCategories; 84 91 Modified: Boolean; 85 92 constructor Create; … … 101 108 end; 102 109 110 { TAcronymEntry } 111 112 constructor TAcronymEntry.Create; 113 begin 114 Categories := TStringList.Create; 115 end; 116 117 destructor TAcronymEntry.Destroy; 118 begin 119 Categories.Free; 120 inherited Destroy; 121 end; 122 103 123 { TAcronymMeanings } 104 124 … … 124 144 constructor TAcronymMeaning.Create; 125 145 begin 126 C ontexts := TAcronymContexts.Create(False);146 Categories := TAcronymCategories.Create(False); 127 147 end; 128 148 129 149 destructor TAcronymMeaning.Destroy; 130 150 begin 131 FreeAndNil(C ontexts);151 FreeAndNil(Categories); 132 152 inherited Destroy; 133 153 end; … … 152 172 end; 153 173 154 { TAcronymC ontexts }155 156 function TAcronymC ontexts.SearchByName(Name: string): TAcronymContext;174 { TAcronymCategories } 175 176 function TAcronymCategories.SearchByName(Name: string): TAcronymCategory; 157 177 var 158 178 I: Integer; 159 179 begin 160 180 I := 0; 161 while (I < Count) and (TAcronymC ontext(Items[I]).Name <> Name) do Inc(I);162 if I < Count then Result := TAcronymC ontext(Items[I])181 while (I < Count) and (TAcronymCategory(Items[I]).Name <> Name) do Inc(I); 182 if I < Count then Result := TAcronymCategory(Items[I]) 163 183 else Result := nil; 164 184 end; 165 185 166 function TAcronymC ontexts.AddContext(Name: string): TAcronymContext;167 begin 168 Result := TAcronymC ontext.Create;186 function TAcronymCategories.AddContext(Name: string): TAcronymCategory; 187 begin 188 Result := TAcronymCategory.Create; 169 189 Result.Name := Name; 170 190 Add(Result); 171 191 end; 172 192 193 procedure TAcronymCategories.AssignToStrings(Strings: TStrings); 194 var 195 I: Integer; 196 begin 197 Strings.Clear; 198 for I := 0 to Count - 1 do 199 Strings.AddObject(TAcronymCategory(Items[I]).Name, Items[I]); 200 end; 201 202 procedure TAcronymCategories.AssignFromStrings(Strings: TStrings); 203 var 204 I: Integer; 205 begin 206 Clear; 207 for I := 0 to Strings.Count - 1 do 208 Add(TAcronymCategory(Strings.Objects[I])); 209 end; 210 173 211 174 212 { TAcronym } … … 185 223 end; 186 224 187 { TAcronymC ontext}188 189 constructor TAcronymC ontext.Create;225 { TAcronymCategory } 226 227 constructor TAcronymCategory.Create; 190 228 begin 191 229 Acronyms := TObjectList.Create(False); 192 230 end; 193 231 194 destructor TAcronymC ontext.Destroy;232 destructor TAcronymCategory.Destroy; 195 233 begin 196 234 FreeAndNil(Acronyms); … … 204 242 Sources := TObjectList.Create; 205 243 Acronyms := TAcronyms.Create; 206 Contexts := TAcronymContexts.Create; 244 Categories := TAcronymCategories.Create; 245 TAcronymCategory(Categories[Categories.Add(TAcronymCategory.Create)]).Name := 'Internet'; 246 TAcronymCategory(Categories[Categories.Add(TAcronymCategory.Create)]).Name := 'Software'; 247 TAcronymCategory(Categories[Categories.Add(TAcronymCategory.Create)]).Name := 'Chat'; 207 248 end; 208 249 … … 211 252 FreeAndNil(Sources); 212 253 FreeAndNil(Acronyms); 213 FreeAndNil(C ontexts);254 FreeAndNil(Categories); 214 255 inherited Destroy; 215 256 end; … … 224 265 I: Integer; 225 266 J: Integer; 226 AcronymContext: TAcronymC ontext;267 AcronymContext: TAcronymCategory; 227 268 begin 228 269 Self.FileName := FileName; … … 252 293 Context.DelimitedText := Line[2]; 253 294 for J := 0 to Context.Count - 1 do begin 254 AcronymContext := C ontexts.SearchByName(Context[J]);295 AcronymContext := Categories.SearchByName(Context[J]); 255 296 if not Assigned(AcronymContext) then begin 256 AcronymContext := TAcronymC ontext.Create;297 AcronymContext := TAcronymCategory.Create; 257 298 AcronymContext.Name := Context[J]; 258 C ontexts.Add(AcronymContext);299 Categories.Add(AcronymContext); 259 300 end; 260 NewMeaning.C ontexts.Add(AcronymContext);301 NewMeaning.Categories.Add(AcronymContext); 261 302 end; 262 303 end; … … 294 335 Line.Add(Name); 295 336 Context.Clear; 296 for J := 0 to C ontexts.Count - 1 do297 Context.Add(TAcronymC ontext(Contexts[J]).Name);337 for J := 0 to Categories.Count - 1 do 338 Context.Add(TAcronymCategory(Categories[J]).Name); 298 339 Line.Add(Context.DelimitedText); 299 340 F.Add(Line.CommaText);
Note:
See TracChangeset
for help on using the changeset viewer.