Changeset 97 for trunk/UAcronym.pas
- Timestamp:
- Aug 22, 2016, 1:16:56 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UAcronym.pas
r89 r97 7 7 uses 8 8 Classes, SysUtils, Contnrs, XMLRead, XMLWrite, DOM, UXMLUtils, 9 SpecializedList, fphttpclient , Dialogs, odbcconn, sqldb;9 SpecializedList, fphttpclient2, Dialogs, odbcconn, sqldb; 10 10 11 11 type … … 13 13 TAcronymMeanings = class; 14 14 TAcronymDb = class; 15 TImportSource = class; 15 16 TImportSources = class; 16 17 TImportFormats = class; … … 73 74 Name: string; 74 75 AcronymMeanings: TAcronymMeanings; 76 ImportSources: TImportSources; 75 77 procedure SaveToNode(Node: TDOMNode); 76 78 procedure LoadFromNode(Node: TDOMNode); … … 93 95 procedure AssignToStrings(Strings: TStrings); 94 96 procedure AssignFromStrings(Strings: TStrings); 97 procedure AddFromStrings(Strings: TStrings); 95 98 function GetString: string; 99 procedure UpdateLinkImportSources(Item: TImportSource); 100 procedure UpdateLinkAcronymMeanings(Item: TAcronymMeaning); 96 101 end; 97 102 … … 108 113 end; 109 114 110 TImportPatternFlag = (ipf None, ipfNewItem, ipfSkip, ipfRemove);111 TImportVariable = (ivNone, ivAcronym, ivMeaning, ivDescription );115 TImportPatternFlag = (ipfSet, ipfNewItem, ipfSkip, ipfRemove, ipfCleanSet); 116 TImportVariable = (ivNone, ivAcronym, ivMeaning, ivDescription, ivCategory); 112 117 113 118 { TImportPattern } … … 244 249 SMeaning = 'Meaning'; 245 250 SAcronym = 'Acronym'; 251 SCategory = 'Category'; 246 252 SNone = 'None'; 247 253 SNewItem = 'New item'; … … 258 264 ImportVariableString[ivMeaning] := SMeaning; 259 265 ImportVariableString[ivDescription] := SDescription; 260 ImportPatternFlagString[ipfNone] := SNone; 266 ImportVariableString[ivCategory] := SCategory; 267 ImportPatternFlagString[ipfSet] := SNone; 261 268 ImportPatternFlagString[ipfNewItem] := SNewItem; 262 269 ImportPatternFlagString[ipfSkip] := SSkip; … … 429 436 I: Integer; 430 437 T: string; 438 TT: string; 431 439 LastLength: Integer; 432 440 AddedAcronym: TAcronymMeaning; 441 NewCategory: TAcronymCategory; 433 442 begin 434 443 NewAcronym := TAcronymEntry.Create; … … 492 501 ivMeaning: NewAcronym.Meaning := T; 493 502 ivDescription: NewAcronym.Description := T; 503 ivCategory: begin 504 NewAcronym.Categories.Clear; 505 while T <> '' do begin 506 if Pos(',', T) > 0 then begin 507 TT := Copy(T, 1, Pos(',', T) - 1); 508 Delete(T, 1, Length(TT) + 1); 509 end else begin 510 TT := T; 511 T := ''; 512 end; 513 TT := Trim(TT); 514 NewCategory := Sources.AcronymDb.Categories.SearchByName(TT); 515 if not Assigned(NewCategory) then begin 516 NewCategory := TAcronymCategory.Create; 517 NewCategory.Name := TT; 518 Sources.AcronymDb.Categories.Add(NewCategory); 519 end; 520 NewAcronym.Categories.AddObject(TT, NewCategory); 521 end; 522 end; 494 523 end; 495 524 end; … … 501 530 AddedAcronym.Description := NewAcronym.Description; 502 531 AddedAcronym.MergeCategories(Categories); 532 AddedAcronym.Categories.AddFromStrings(NewAcronym.Categories); 533 AddedAcronym.Categories.UpdateLinkAcronymMeanings(AddedAcronym); 503 534 if AddedAcronym.Sources.IndexOf(Self) = -1 then 504 535 AddedAcronym.Sources.Add(Self); … … 877 908 var 878 909 Node2: TDOMNode; 910 I: Integer; 879 911 begin 880 912 Name := ReadString(Node, 'Name', ''); … … 890 922 if Assigned(Node2) then 891 923 Categories.LoadRefFromNode(Node2); 924 925 // Add reverse references 926 for I := 0 to Categories.Count - 1 do 927 TAcronymCategory(Categories[I]).ImportSources.Add(Self); 892 928 end; 893 929 … … 902 938 903 939 destructor TImportSource.Destroy; 904 begin 940 var 941 I: Integer; 942 begin 943 for I := 0 to Categories.Count - 1 do 944 TAcronymCategory(Categories[I]).ImportSources.Remove(Self); 945 FreeAndNil(Categories); 905 946 FreeAndNil(ResponseStream); 906 FreeAndNil(Categories);907 947 inherited Destroy; 908 948 end; … … 1245 1285 1246 1286 procedure TAcronymCategories.AssignFromStrings(Strings: TStrings); 1247 var1248 I: Integer;1249 1287 begin 1250 1288 Clear; 1289 AddFromStrings(Strings); 1290 end; 1291 1292 procedure TAcronymCategories.AddFromStrings(Strings: TStrings); 1293 var 1294 I: Integer; 1295 begin 1251 1296 for I := 0 to Strings.Count - 1 do begin 1252 1297 Add(TAcronymCategory(Strings.Objects[I])); … … 1264 1309 end; 1265 1310 1311 procedure TAcronymCategories.UpdateLinkImportSources(Item: TImportSource); 1312 var 1313 I: Integer; 1314 begin 1315 for I := 0 to Count - 1 do 1316 if TAcronymCategory(Items[I]).ImportSources.IndexOf(Item) = -1 then 1317 TAcronymCategory(Items[I]).ImportSources.Add(Item); 1318 end; 1319 1320 procedure TAcronymCategories.UpdateLinkAcronymMeanings(Item: TAcronymMeaning); 1321 var 1322 I: Integer; 1323 begin 1324 for I := 0 to Count - 1 do 1325 if TAcronymCategory(Items[I]).AcronymMeanings.IndexOf(Item) = -1 then 1326 TAcronymCategory(Items[I]).AcronymMeanings.Add(Item); 1327 end; 1328 1266 1329 1267 1330 { TAcronym } … … 1318 1381 begin 1319 1382 AcronymMeanings := TAcronymMeanings.Create(False); 1383 ImportSources := TImportSources.Create(False); 1320 1384 end; 1321 1385 … … 1327 1391 TAcronymMeaning(AcronymMeanings[I]).Categories.Remove(Self); 1328 1392 FreeAndNil(AcronymMeanings); 1393 for I := 0 to ImportSources.Count - 1 do 1394 TImportSource(ImportSources[I]).Categories.Remove(Self); 1395 FreeAndNil(ImportSources); 1329 1396 inherited Destroy; 1330 1397 end;
Note:
See TracChangeset
for help on using the changeset viewer.