Changeset 13 for trunk/UAcronym.pas


Ignore:
Timestamp:
Apr 28, 2016, 10:09:02 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Acronym meaning context items renamed to categories.
  • Added: Ability to select categories for meanings.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UAcronym.pas

    r8 r13  
    99
    1010type
    11   TAcronymContexts = class;
     11  TAcronymCategories = class;
    1212  TAcronymMeanings = class;
    1313
     
    3333    Language: string;
    3434    Acronym: TAcronym;
    35     Contexts: TAcronymContexts;
     35    Categories: TAcronymCategories;
    3636    Source: TAcronymSource;
    3737    constructor Create;
     
    5353  end;
    5454
    55   { TAcronymContext }
    56 
    57   TAcronymContext = class
     55  { TAcronymCategory }
     56
     57  TAcronymCategory = class
    5858    Name: string;
    5959    Acronyms: TObjectList; // TObjectList<TAcronym>
     
    6262  end;
    6363
    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 }
    7074
    7175  TAcronymEntry = class
     
    7377    Meaning: string;
    7478    Description: string;
     79    Categories: TStringList;
     80    constructor Create;
     81    destructor Destroy; override;
    7582  end;
    7683
     
    8188    Sources: TObjectList; // TObjectList<TAcronymSource>
    8289    Acronyms: TAcronyms;
    83     Contexts: TAcronymContexts;
     90    Categories: TAcronymCategories;
    8491    Modified: Boolean;
    8592    constructor Create;
     
    101108end;
    102109
     110{ TAcronymEntry }
     111
     112constructor TAcronymEntry.Create;
     113begin
     114  Categories := TStringList.Create;
     115end;
     116
     117destructor TAcronymEntry.Destroy;
     118begin
     119  Categories.Free;
     120  inherited Destroy;
     121end;
     122
    103123{ TAcronymMeanings }
    104124
     
    124144constructor TAcronymMeaning.Create;
    125145begin
    126   Contexts := TAcronymContexts.Create(False);
     146  Categories := TAcronymCategories.Create(False);
    127147end;
    128148
    129149destructor TAcronymMeaning.Destroy;
    130150begin
    131   FreeAndNil(Contexts);
     151  FreeAndNil(Categories);
    132152  inherited Destroy;
    133153end;
     
    152172end;
    153173
    154 { TAcronymContexts }
    155 
    156 function TAcronymContexts.SearchByName(Name: string): TAcronymContext;
     174{ TAcronymCategories }
     175
     176function TAcronymCategories.SearchByName(Name: string): TAcronymCategory;
    157177var
    158178  I: Integer;
    159179begin
    160180  I := 0;
    161   while (I < Count) and (TAcronymContext(Items[I]).Name <> Name) do Inc(I);
    162   if I < Count then Result := TAcronymContext(Items[I])
     181  while (I < Count) and (TAcronymCategory(Items[I]).Name <> Name) do Inc(I);
     182  if I < Count then Result := TAcronymCategory(Items[I])
    163183    else Result := nil;
    164184end;
    165185
    166 function TAcronymContexts.AddContext(Name: string): TAcronymContext;
    167 begin
    168   Result := TAcronymContext.Create;
     186function TAcronymCategories.AddContext(Name: string): TAcronymCategory;
     187begin
     188  Result := TAcronymCategory.Create;
    169189  Result.Name := Name;
    170190  Add(Result);
    171191end;
    172192
     193procedure TAcronymCategories.AssignToStrings(Strings: TStrings);
     194var
     195  I: Integer;
     196begin
     197  Strings.Clear;
     198  for I := 0 to Count - 1 do
     199    Strings.AddObject(TAcronymCategory(Items[I]).Name, Items[I]);
     200end;
     201
     202procedure TAcronymCategories.AssignFromStrings(Strings: TStrings);
     203var
     204  I: Integer;
     205begin
     206  Clear;
     207  for I := 0 to Strings.Count - 1 do
     208    Add(TAcronymCategory(Strings.Objects[I]));
     209end;
     210
    173211
    174212{ TAcronym }
     
    185223end;
    186224
    187 { TAcronymContext }
    188 
    189 constructor TAcronymContext.Create;
     225{ TAcronymCategory }
     226
     227constructor TAcronymCategory.Create;
    190228begin
    191229  Acronyms := TObjectList.Create(False);
    192230end;
    193231
    194 destructor TAcronymContext.Destroy;
     232destructor TAcronymCategory.Destroy;
    195233begin
    196234  FreeAndNil(Acronyms);
     
    204242  Sources := TObjectList.Create;
    205243  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';
    207248end;
    208249
     
    211252  FreeAndNil(Sources);
    212253  FreeAndNil(Acronyms);
    213   FreeAndNil(Contexts);
     254  FreeAndNil(Categories);
    214255  inherited Destroy;
    215256end;
     
    224265  I: Integer;
    225266  J: Integer;
    226   AcronymContext: TAcronymContext;
     267  AcronymContext: TAcronymCategory;
    227268begin
    228269  Self.FileName := FileName;
     
    252293      Context.DelimitedText := Line[2];
    253294      for J := 0 to Context.Count - 1 do begin
    254         AcronymContext := Contexts.SearchByName(Context[J]);
     295        AcronymContext := Categories.SearchByName(Context[J]);
    255296        if not Assigned(AcronymContext) then begin
    256           AcronymContext := TAcronymContext.Create;
     297          AcronymContext := TAcronymCategory.Create;
    257298          AcronymContext.Name := Context[J];
    258           Contexts.Add(AcronymContext);
     299          Categories.Add(AcronymContext);
    259300        end;
    260         NewMeaning.Contexts.Add(AcronymContext);
     301        NewMeaning.Categories.Add(AcronymContext);
    261302      end;
    262303    end;
     
    294335        Line.Add(Name);
    295336        Context.Clear;
    296         for J := 0 to Contexts.Count - 1 do
    297           Context.Add(TAcronymContext(Contexts[J]).Name);
     337        for J := 0 to Categories.Count - 1 do
     338          Context.Add(TAcronymCategory(Categories[J]).Name);
    298339        Line.Add(Context.DelimitedText);
    299340        F.Add(Line.CommaText);
Note: See TracChangeset for help on using the changeset viewer.