Changeset 95 for trunk/Forms


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.
Location:
trunk/Forms
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormAcronym.pas

    r89 r95  
    7575  I: Integer;
    7676begin
    77   FormCategorySelect.Load(ListBoxCategories.Items);
    78   if FormCategorySelect.ShowModal = mrOk then begin
    79     for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
    80       if FormCategorySelect.ListBox1.Selected[I] then begin
    81         ListBoxCategories.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
    82       end;
     77  FormCategorySelect := TFormCategorySelect.Create(Self);
     78  try
     79    FormCategorySelect.Load(ListBoxCategories.Items);
     80    if FormCategorySelect.ShowModal = mrOk then begin
     81      for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
     82        if FormCategorySelect.ListBox1.Selected[I] then begin
     83          ListBoxCategories.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
     84        end;
     85    end;
     86  finally
     87    FreeAndNil(FormCategorySelect);
    8388  end;
    8489end;
  • 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;
  • trunk/Forms/UFormExport.lfm

    r90 r95  
    11object FormExport: TFormExport
    2   Left = 722
     2  Left = 281
    33  Height = 654
    4   Top = 491
     4  Top = 221
    55  Width = 850
    66  Caption = 'Export'
    77  ClientHeight = 654
    88  ClientWidth = 850
     9  Position = poScreenCenter
    910  LCLVersion = '1.6.0.4'
    1011  object ButtonProcess: TButton
     
    1920  object ComboBoxDataFormat: TComboBox
    2021    Left = 341
    21     Height = 34
     22    Height = 28
    2223    Top = 5
    2324    Width = 182
    24     ItemHeight = 0
     25    ItemHeight = 20
    2526    ItemIndex = 0
    2627    Items.Strings = (
  • trunk/Forms/UFormImportFormat.lfm

    r69 r95  
    171171    object AAdd: TAction
    172172      Caption = 'Add'
     173      ImageIndex = 0
    173174      OnExecute = AAddExecute
    174175      ShortCut = 45
     
    176177    object AModify: TAction
    177178      Caption = 'Modify'
     179      ImageIndex = 3
    178180      OnExecute = AModifyExecute
    179181      ShortCut = 13
     
    181183    object ARemove: TAction
    182184      Caption = 'Remove'
     185      ImageIndex = 4
    183186      OnExecute = ARemoveExecute
    184187      ShortCut = 46
  • trunk/Forms/UFormImportFormat.pas

    r31 r95  
    8080  NewImportPattern: TImportPattern;
    8181begin
    82   NewImportPattern := TImportPattern.Create;
    83   FormImportPattern.Load(NewImportPattern);
    84   if FormImportPattern.ShowModal = mrOk then begin
    85     FormImportPattern.Save(NewImportPattern);
    86     ImportFormat.ItemPatterns.Add(NewImportPattern);
    87     NewImportPattern := nil;
    88     ReloadList;
    89   end;
    90   if Assigned(NewImportPattern) then NewImportPattern.Free;
    91 end;
    92 
    93 procedure TFormImportFormat.AModifyExecute(Sender: TObject);
    94 var
    95   NewImportPattern: TImportPattern;
    96 begin
    97   if Assigned(ListViewItemRules.Selected) then begin
     82  FormImportPattern := TFormImportPattern.Create(Self);
     83  try
    9884    NewImportPattern := TImportPattern.Create;
    99     NewImportPattern.Assign(ListViewItemRules.Selected.Data);
    10085    FormImportPattern.Load(NewImportPattern);
    10186    if FormImportPattern.ShowModal = mrOk then begin
    10287      FormImportPattern.Save(NewImportPattern);
    103       TImportPattern(ListViewItemRules.Selected.Data).Assign(NewImportPattern);
     88      ImportFormat.ItemPatterns.Add(NewImportPattern);
     89      NewImportPattern := nil;
    10490      ReloadList;
    10591    end;
    10692    if Assigned(NewImportPattern) then NewImportPattern.Free;
     93  finally
     94    FreeAndNil(FormImportPattern);
     95  end;
     96end;
     97
     98procedure TFormImportFormat.AModifyExecute(Sender: TObject);
     99var
     100  NewImportPattern: TImportPattern;
     101begin
     102  FormImportPattern := TFormImportPattern.Create(Self);
     103  try
     104    if Assigned(ListViewItemRules.Selected) then begin
     105      NewImportPattern := TImportPattern.Create;
     106      NewImportPattern.Assign(ListViewItemRules.Selected.Data);
     107      FormImportPattern.Load(NewImportPattern);
     108      if FormImportPattern.ShowModal = mrOk then begin
     109        FormImportPattern.Save(NewImportPattern);
     110        TImportPattern(ListViewItemRules.Selected.Data).Assign(NewImportPattern);
     111        ReloadList;
     112      end;
     113      if Assigned(NewImportPattern) then NewImportPattern.Free;
     114    end;
     115  finally
     116    FreeAndNil(FormImportPattern);
    107117  end;
    108118end;
  • trunk/Forms/UFormImportFormats.pas

    r86 r95  
    112112  NewImportFormat := TImportFormat.Create;
    113113  NewImportFormat.Formats := ImportFormats;
    114   FormImportFormat.Load(NewImportFormat);
    115   if FormImportFormat.ShowModal = mrOk then begin
    116     FormImportFormat.Save(NewImportFormat);
    117     if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
    118       ImportFormats.Add(NewImportFormat);
    119       NewImportFormat := nil;
    120       Core.AcronymDb.Modified := True;
    121       UpdateList;
    122     end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
     114  FormImportFormat := TFormImportFormat.Create(Self);
     115  try
     116    FormImportFormat.Load(NewImportFormat);
     117    if FormImportFormat.ShowModal = mrOk then begin
     118      FormImportFormat.Save(NewImportFormat);
     119      if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
     120        ImportFormats.Add(NewImportFormat);
     121        NewImportFormat := nil;
     122        Core.AcronymDb.Modified := True;
     123        UpdateList;
     124      end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
     125    end;
     126    if Assigned(NewImportFormat) then NewImportFormat.Free;
     127  finally
     128    FreeAndNil(FormImportFormat);
    123129  end;
    124   if Assigned(NewImportFormat) then NewImportFormat.Free;
    125130end;
    126131
     
    132137    NewImportFormat := TImportFormat.Create;
    133138    NewImportFormat.Assign(ListView1.Selected.Data);
    134     FormImportFormat.Load(NewImportFormat);
    135     if FormImportFormat.ShowModal = mrOk then begin
    136       FormImportFormat.Save(NewImportFormat);
    137       if (NewImportFormat.Name <> TImportFormat(ListView1.Selected.Data).Name) then begin
    138         if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
     139    FormImportFormat := TFormImportFormat.Create(Self);
     140    try
     141      FormImportFormat.Load(NewImportFormat);
     142      if FormImportFormat.ShowModal = mrOk then begin
     143        FormImportFormat.Save(NewImportFormat);
     144        if (NewImportFormat.Name <> TImportFormat(ListView1.Selected.Data).Name) then begin
     145          if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
     146            TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
     147            Core.AcronymDb.Modified := True;
     148            UpdateList;
     149          end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
     150        end else begin
    139151          TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
    140152          Core.AcronymDb.Modified := True;
    141153          UpdateList;
    142         end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
    143       end else begin
    144         TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
    145         Core.AcronymDb.Modified := True;
    146         UpdateList;
     154        end;
    147155      end;
     156      if Assigned(NewImportFormat) then NewImportFormat.Free;
     157    finally
     158      FreeAndNil(FormImportFormat);
    148159    end;
    149     if Assigned(NewImportFormat) then NewImportFormat.Free;
    150160  end;
    151161end;
  • trunk/Forms/UFormImportSource.pas

    r89 r95  
    7272    NewImportFormat := TImportFormat.Create;
    7373    NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
    74     FormImportFormat.Load(NewImportFormat);
    75     if FormImportFormat.ShowModal = mrOk then begin
    76       FormImportFormat.Save(NewImportFormat);
    77       TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
    78       Core.AcronymDb.Modified := True;
    79       ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
     74    FormImportFormat := TFormImportFormat.Create(Self);
     75    try
     76      FormImportFormat.Load(NewImportFormat);
     77      if FormImportFormat.ShowModal = mrOk then begin
     78        FormImportFormat.Save(NewImportFormat);
     79        TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
     80        Core.AcronymDb.Modified := True;
     81        ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
     82      end;
     83      if Assigned(NewImportFormat) then NewImportFormat.Free;
     84    finally
     85      FreeAndNil(FormImportFormat);
    8086    end;
    81     if Assigned(NewImportFormat) then NewImportFormat.Free;
    8287  end;
    8388end;
     
    97102  I: Integer;
    98103begin
    99   FormCategorySelect.Load(ListBox1.Items);
    100   if FormCategorySelect.ShowModal = mrOk then begin
    101     for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
    102       if FormCategorySelect.ListBox1.Selected[I] then begin
    103         ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
    104       end;
     104  FormCategorySelect := TFormCategorySelect.Create(Self);
     105  try
     106    FormCategorySelect.Load(ListBox1.Items);
     107    if FormCategorySelect.ShowModal = mrOk then begin
     108      for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
     109        if FormCategorySelect.ListBox1.Selected[I] then begin
     110          ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
     111        end;
     112    end;
     113  finally
     114    FreeAndNil(FormCategorySelect);
    105115  end;
    106116end;
  • trunk/Forms/UFormImportSources.pas

    r86 r95  
    187187  NewImportSource := TImportSource.Create;
    188188  NewImportSource.Sources := ImportSources;
    189   FormImportSource.Load(NewImportSource);
    190   if FormImportSource.ShowModal = mrOk then begin
    191     FormImportSource.Save(NewImportSource);
    192     if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
    193       ImportSources.Add(NewImportSource);
    194       NewImportSource := nil;
    195       Core.AcronymDb.Modified := True;
    196       UpdateList;
    197     end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
    198   end;
    199   if Assigned(NewImportSource) then NewImportSource.Free;
     189  FormImportSource := TFormImportSource.Create(Self);
     190  try
     191    FormImportSource.Load(NewImportSource);
     192    if FormImportSource.ShowModal = mrOk then begin
     193      FormImportSource.Save(NewImportSource);
     194      if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
     195        ImportSources.Add(NewImportSource);
     196        NewImportSource := nil;
     197        Core.AcronymDb.Modified := True;
     198        UpdateList;
     199      end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
     200    end;
     201    if Assigned(NewImportSource) then NewImportSource.Free;
     202  finally
     203    FreeAndNil(FormImportSource);
     204  end;
    200205end;
    201206
     
    227232    NewImportSource := TImportSource.Create;
    228233    NewImportSource.Assign(ListView1.Selected.Data);
    229     FormImportSource.Load(NewImportSource);
    230     if FormImportSource.ShowModal = mrOk then begin
    231       FormImportSource.Save(NewImportSource);
    232       if (NewImportSource.Name <> TImportSource(ListView1.Selected.Data).Name) then begin
    233         if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
     234    FormImportSource := TFormImportSource.Create(Self);
     235    try
     236      FormImportSource.Load(NewImportSource);
     237      if FormImportSource.ShowModal = mrOk then begin
     238        FormImportSource.Save(NewImportSource);
     239        if (NewImportSource.Name <> TImportSource(ListView1.Selected.Data).Name) then begin
     240          if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
     241            TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
     242            Core.AcronymDb.Modified := True;
     243            UpdateList;
     244          end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
     245        end else begin
    234246          TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
    235247          Core.AcronymDb.Modified := True;
    236248          UpdateList;
    237         end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
    238       end else begin
    239         TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
    240         Core.AcronymDb.Modified := True;
    241         UpdateList;
     249        end;
    242250      end;
    243     end;
    244     if Assigned(NewImportSource) then NewImportSource.Free;
     251      if Assigned(NewImportSource) then NewImportSource.Free;
     252    finally
     253      FreeAndNil(FormImportSource);
     254    end;
    245255  end;
    246256end;
  • trunk/Forms/UFormMain.lfm

    r90 r95  
    55  Width = 782
    66  Caption = 'Acronym Decoder'
    7   ClientHeight = 414
     7  ClientHeight = 421
    88  ClientWidth = 782
    99  Menu = MainMenu1
     
    1717  object Panel1: TPanel
    1818    Left = 0
    19     Height = 388
     19    Height = 395
    2020    Top = 26
    2121    Width = 782
    2222    Align = alClient
    2323    BevelOuter = bvNone
    24     ClientHeight = 388
     24    ClientHeight = 395
    2525    ClientWidth = 782
    2626    TabOrder = 1
    2727    object CheckBoxExactMath: TCheckBox
    2828      Left = 8
    29       Height = 28
     29      Height = 24
    3030      Top = 3
    31       Width = 129
     31      Width = 104
    3232      Caption = 'Exact match'
    3333      OnChange = CheckBoxExactMathChange
     
    4444    object ListViewAcronyms: TListView
    4545      Left = 8
    46       Height = 316
     46      Height = 323
    4747      Top = 64
    4848      Width = 767
  • trunk/Forms/UFormMain.pas

    r91 r95  
    207207procedure TFormMain.AExportExecute(Sender: TObject);
    208208begin
    209   FormExport.ShowModal;
     209  FormExport := TFormExport.Create(Self);
     210  try
     211    FormExport.ShowModal;
     212  finally
     213    FreeAndNil(FormExport);
     214  end;
    210215end;
    211216
     
    281286procedure TFormMain.AImportExecute(Sender: TObject);
    282287begin
    283   FormImport.ShowModal;
    284   UpdateAcronymsList;
    285   UpdateInterface;
     288  FormImport := TFormImport.Create(Self);
     289  try
     290    FormImport.ShowModal;
     291    UpdateAcronymsList;
     292    UpdateInterface;
     293  finally
     294    FreeAndNil(FormImport);
     295  end;
    286296end;
    287297
     
    314324procedure TFormMain.ASettingsExecute(Sender: TObject);
    315325begin
    316   FormSettings.Load;
    317   if FormSettings.ShowModal = mrOk then begin
     326  FormSettings := TFormSettings.Create(Self);
     327  try
     328    FormSettings.Load;
     329    if FormSettings.ShowModal = mrOk then begin
    318330    FormSettings.Save;
    319     Core.SaveConfig;
     331      Core.SaveConfig;
     332    end;
     333  finally
     334    FreeAndNil(FormSettings);
    320335  end;
    321336end;
     
    323338procedure TFormMain.AShowAboutExecute(Sender: TObject);
    324339begin
    325   FormAbout.ShowModal;
     340  FormAbout := TFormAbout.Create(Self);
     341  try
     342    FormAbout.ShowModal;
     343  finally
     344    FreeAndNil(FormAbout);
     345  end;
    326346end;
    327347
    328348procedure TFormMain.AShowAcronymsExecute(Sender: TObject);
    329349begin
    330   FormAcronyms.ShowModal;
    331   UpdateAcronymsList;
    332   UpdateInterface;
     350  FormAcronyms := TFormAcronyms.Create(Self);
     351  try
     352    FormAcronyms.ShowModal;
     353    UpdateAcronymsList;
     354    UpdateInterface;
     355  finally
     356    FreeAndNil(FormAcronyms);
     357  end;
    333358end;
    334359
    335360procedure TFormMain.AShowCategoriesExecute(Sender: TObject);
    336361begin
    337   FormCategories.Categories := Core.AcronymDb.Categories;
    338   FormCategories.ShowModal;
    339   UpdateAcronymsList;
    340   UpdateInterface;
     362  FormCategories := TFormCategories.Create(Self);
     363  try
     364    FormCategories.Categories := Core.AcronymDb.Categories;
     365    FormCategories.ShowModal;
     366    UpdateAcronymsList;
     367    UpdateInterface;
     368  finally
     369    FreeAndNil(FormCategories);
     370  end;
    341371end;
    342372
     
    349379procedure TFormMain.AShowImportFormatsExecute(Sender: TObject);
    350380begin
    351   FormImportFormats.ImportFormats := Core.AcronymDb.ImportFormats;
    352   FormImportFormats.ShowModal;
    353   UpdateInterface;
     381  FormImportFormats := TFormImportFormats.Create(Self);
     382  try
     383    FormImportFormats.ImportFormats := Core.AcronymDb.ImportFormats;
     384    FormImportFormats.ShowModal;
     385    UpdateInterface;
     386  finally
     387    FreeAndNil(FormImportFormats);
     388  end;
    354389end;
    355390
    356391procedure TFormMain.AShowImportSourcesExecute(Sender: TObject);
    357392begin
    358   FormImportSources.ImportSources := Core.AcronymDb.ImportSources;
    359   FormImportSources.ShowModal;
    360   UpdateAcronymsList;
    361   UpdateInterface;
     393  FormImportSources := TFormImportSources.Create(Self);
     394  try
     395    FormImportSources.ImportSources := Core.AcronymDb.ImportSources;
     396    FormImportSources.ShowModal;
     397    UpdateAcronymsList;
     398    UpdateInterface;
     399  finally
     400    FreeAndNil(FormImportSources);
     401  end;
    362402end;
    363403
Note: See TracChangeset for help on using the changeset viewer.