Changeset 14 for trunk/UAcronym.pas


Ignore:
Timestamp:
Apr 28, 2016, 10:56:31 PM (8 years ago)
Author:
chronos
Message:
  • Added: Window for acronym categories management. There acronyms can be added, modifed and removed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UAcronym.pas

    r13 r14  
    1515    Name: string;
    1616    URL: string;
     17  end;
     18
     19  TAcronymSources = class(TObjectList)
     20
    1721  end;
    1822
     
    5761  TAcronymCategory = class
    5862    Name: string;
    59     Acronyms: TObjectList; // TObjectList<TAcronym>
     63    AcronymMeanings: TAcronymMeanings;
    6064    constructor Create;
    6165    destructor Destroy; override;
     
    8690  TAcronymDb = class
    8791    FileName: string;
    88     Sources: TObjectList; // TObjectList<TAcronymSource>
     92    Sources: TAcronymSources;
    8993    Acronyms: TAcronyms;
    9094    Categories: TAcronymCategories;
     
    148152
    149153destructor TAcronymMeaning.Destroy;
    150 begin
     154var
     155  I: Integer;
     156begin
     157  for I := 0 to Categories.Count - 1 do
     158    TAcronymCategory(Categories[I]).AcronymMeanings.Remove(Self);
    151159  FreeAndNil(Categories);
    152160  inherited Destroy;
     
    205213begin
    206214  Clear;
    207   for I := 0 to Strings.Count - 1 do
     215  for I := 0 to Strings.Count - 1 do begin
    208216    Add(TAcronymCategory(Strings.Objects[I]));
     217  end;
    209218end;
    210219
     
    227236constructor TAcronymCategory.Create;
    228237begin
    229   Acronyms := TObjectList.Create(False);
     238  AcronymMeanings := TAcronymMeanings.Create(False);
    230239end;
    231240
    232241destructor TAcronymCategory.Destroy;
    233 begin
    234   FreeAndNil(Acronyms);
     242var
     243  I: Integer;
     244begin
     245  for I := 0 to AcronymMeanings.Count - 1 do
     246    TAcronymMeaning(AcronymMeanings[I]).Categories.Remove(Self);
     247  FreeAndNil(AcronymMeanings);
    235248  inherited Destroy;
    236249end;
     
    240253constructor TAcronymDb.Create;
    241254begin
    242   Sources := TObjectList.Create;
     255  Sources := TAcronymSources.Create;
    243256  Acronyms := TAcronyms.Create;
    244257  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';
    248258end;
    249259
     
    260270  F: TStringList;
    261271  Line: TStringList;
    262   Context: TStringList;
     272  CategoryStrings: TStringList;
    263273  NewAcronym: TAcronym;
    264274  NewMeaning: TAcronymMeaning;
    265275  I: Integer;
    266276  J: Integer;
    267   AcronymContext: TAcronymCategory;
     277  AcronymCategory: TAcronymCategory;
    268278begin
    269279  Self.FileName := FileName;
     
    272282  Line := TStringList.Create;
    273283  Line.StrictDelimiter := True;
    274   Context := TStringList.Create;
    275   Context.Delimiter := ';';
     284  CategoryStrings := TStringList.Create;
     285  CategoryStrings.Delimiter := ';';
    276286  try
    277287    F.LoadFromFile(FileName);
     
    291301        NewAcronym.Meanings.Add(NewMeaning);
    292302      end;
    293       Context.DelimitedText := Line[2];
    294       for J := 0 to Context.Count - 1 do begin
    295         AcronymContext := Categories.SearchByName(Context[J]);
    296         if not Assigned(AcronymContext) then begin
    297           AcronymContext := TAcronymCategory.Create;
    298           AcronymContext.Name := Context[J];
    299           Categories.Add(AcronymContext);
     303      CategoryStrings.DelimitedText := Line[2];
     304      for J := 0 to CategoryStrings.Count - 1 do begin
     305        AcronymCategory := Categories.SearchByName(CategoryStrings[J]);
     306        if not Assigned(AcronymCategory) then begin
     307          AcronymCategory := TAcronymCategory.Create;
     308          AcronymCategory.Name := CategoryStrings[J];
     309          Categories.Add(AcronymCategory);
    300310        end;
    301         NewMeaning.Categories.Add(AcronymContext);
     311        NewMeaning.Categories.Add(AcronymCategory);
     312        AcronymCategory.AcronymMeanings.Add(NewMeaning);
    302313      end;
    303314    end;
     
    305316    F.Free;
    306317    Line.Free;
    307     Context.Free;
     318    CategoryStrings.Free;
    308319  end;
    309320  Modified := False;
Note: See TracChangeset for help on using the changeset viewer.