Changeset 4 for trunk/UAcronym.pas


Ignore:
Timestamp:
Apr 20, 2016, 11:11:26 PM (9 years ago)
Author:
chronos
Message:
  • Added: Now it is possible to add, modify, remove and remove all acronyms.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UAcronym.pas

    r1 r4  
    4242  TAcronymMeanings = class(TObjectList)
    4343    function SearchByName(Name: string): TAcronymMeaning;
     44    function AddMeaning(Name: string): TAcronymMeaning;
    4445  end;
    4546
     
    4849  TAcronyms = class(TObjectList)
    4950    function SearchByName(Name: string): TAcronym;
     51    function AddAcronym(Name: string): TAcronym;
    5052  end;
    5153
     
    6365  TAcronymContexts = class(TObjectList)
    6466    function SearchByName(Name: string): TAcronymContext;
     67    function AddContext(Name: string): TAcronymContext;
     68  end;
     69
     70  TAcronymEntry = class
     71    Name: string;
     72    Meaning: string;
    6573  end;
    6674
     
    7684    procedure SaveToFile(FileName: string);
    7785    procedure FilterList(AName: string; Items: TAcronymMeanings);
     86    procedure AddAcronym(AcronymName, MeaningName: string);
     87    procedure RemoveAcronym(AcronymName, MeaningName: string);
    7888  end;
    7989
     
    92102end;
    93103
     104function TAcronymMeanings.AddMeaning(Name: string): TAcronymMeaning;
     105begin
     106  Result := TAcronymMeaning.Create;
     107  Result.Name := Name;
     108  Add(Result);
     109end;
     110
    94111{ TAcronymMeaning }
    95112
     
    117134end;
    118135
     136function TAcronyms.AddAcronym(Name: string): TAcronym;
     137begin
     138  Result := TAcronym.Create;
     139  Result.Name := Name;
     140  Add(Result);
     141end;
     142
    119143{ TAcronymContexts }
    120144
     
    127151  if I < Count then Result := TAcronymContext(Items[I])
    128152    else Result := nil;
     153end;
     154
     155function TAcronymContexts.AddContext(Name: string): TAcronymContext;
     156begin
     157  Result := TAcronymContext.Create;
     158  Result.Name := Name;
     159  Add(Result);
    129160end;
    130161
     
    280311end;
    281312
     313procedure TAcronymDb.AddAcronym(AcronymName, MeaningName: string);
     314var
     315  Acronym: TAcronym;
     316  Meaning: TAcronymMeaning;
     317begin
     318  Acronym := Acronyms.SearchByName(AcronymName);
     319  if not Assigned(Acronym) then begin
     320    Acronym := TAcronym.Create;
     321    Acronym.Name := AcronymName;
     322    Acronyms.Add(Acronym);
     323  end;
     324  Meaning := Acronym.Meanings.SearchByName(MeaningName);
     325  if not Assigned(Meaning) then begin
     326    Meaning := TAcronymMeaning.Create;
     327    Meaning.Name := MeaningName;
     328    Meaning.Acronym := Acronym;
     329    Acronym.Meanings.Add(Meaning);
     330  end;
     331end;
     332
     333procedure TAcronymDb.RemoveAcronym(AcronymName, MeaningName: string);
     334var
     335  Acronym: TAcronym;
     336  Meaning: TAcronymMeaning;
     337begin
     338  Acronym := Acronyms.SearchByName(AcronymName);
     339  if Assigned(Acronym) then begin
     340    Meaning := Acronym.Meanings.SearchByName(MeaningName);
     341    if Assigned(Meaning) then begin
     342      Acronym.Meanings.Remove(Meaning);
     343      if Acronym.Meanings.Count = 0 then
     344        Acronyms.Remove(Acronym);
     345    end;
     346  end;
     347end;
     348
    282349end.
    283350
Note: See TracChangeset for help on using the changeset viewer.