Ignore:
Timestamp:
Aug 17, 2016, 11:20:37 AM (8 years ago)
Author:
chronos
Message:
  • Modified: Do not initialize all forms at startup to save some memory.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormAcronyms.pas

    r89 r95  
    123123  TempEntry.Meaning := '';
    124124  TempEntry.Description := '';
    125   FormAcronym.Load(TempEntry);
    126   if FormAcronym.ShowModal = mrOk then begin
    127     FormAcronym.Save(TempEntry);
    128     Meaning := Core.AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning);
    129     Meaning.Description := TempEntry.Description;
    130     Meaning.Categories.AssignFromStrings(TempEntry.Categories);
    131     for I := 0 to Meaning.Categories.Count - 1 do
    132       TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning);
    133     UpdateAcronymsList;
    134     UpdateInterface;
     125  FormAcronym := TFormAcronym.Create(Self);
     126  try
     127    FormAcronym.Load(TempEntry);
     128    if FormAcronym.ShowModal = mrOk then begin
     129      FormAcronym.Save(TempEntry);
     130      Meaning := Core.AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning);
     131      Meaning.Description := TempEntry.Description;
     132      Meaning.Categories.AssignFromStrings(TempEntry.Categories);
     133      for I := 0 to Meaning.Categories.Count - 1 do
     134        TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning);
     135      UpdateAcronymsList;
     136      UpdateInterface;
     137    end;
     138  finally
     139    FreeAndNil(FormAcronym);
    135140  end;
    136141  TempEntry.Free;
     
    154159    TempCategories := TStringList.Create;
    155160    TempCategories.Assign(TempEntry.Categories);
    156     FormAcronym.Load(TempEntry);
    157     if FormAcronym.ShowModal = mrOk then begin
    158       FormAcronym.Save(TempEntry);
    159       if (TempEntry.Name <> Acronym.Name) or
    160       (TempEntry.Meaning <> Name) or
    161       (TempEntry.Description <> Description) or
    162       not FormMain.CompareStrings(TempEntry.Categories, TempCategories) then begin
    163         // TODO: Update item inplace if possible
    164         Core.AcronymDb.RemoveMeaning(TAcronymMeaning(ListViewAcronyms.Selected.Data));
    165         Meaning := Core.AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning);
    166         Meaning.Description := TempEntry.Description;
    167         Meaning.Categories.AssignFromStrings(TempEntry.Categories);
    168         for I := 0 to Meaning.Categories.Count - 1 do
    169           TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning);
    170         UpdateAcronymsList;
    171         UpdateInterface;
     161    FormAcronym := TFormAcronym.Create(Self);
     162    try
     163      FormAcronym.Load(TempEntry);
     164      if FormAcronym.ShowModal = mrOk then begin
     165        FormAcronym.Save(TempEntry);
     166        if (TempEntry.Name <> Acronym.Name) or
     167        (TempEntry.Meaning <> Name) or
     168        (TempEntry.Description <> Description) or
     169        not FormMain.CompareStrings(TempEntry.Categories, TempCategories) then begin
     170          // TODO: Update item inplace if possible
     171          Core.AcronymDb.RemoveMeaning(TAcronymMeaning(ListViewAcronyms.Selected.Data));
     172          Meaning := Core.AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning);
     173          Meaning.Description := TempEntry.Description;
     174          Meaning.Categories.AssignFromStrings(TempEntry.Categories);
     175          for I := 0 to Meaning.Categories.Count - 1 do
     176            TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning);
     177          UpdateAcronymsList;
     178          UpdateInterface;
     179        end;
    172180      end;
    173     end;
    174     TempEntry.Free;
    175     TempCategories.Free;
     181    finally
     182      FreeAndNil(FormAcronym);
     183      FreeAndNil(TempEntry);
     184      FreeAndNil(TempCategories);
     185    end;
    176186  end;
    177187end;
Note: See TracChangeset for help on using the changeset viewer.