Ignore:
Timestamp:
Sep 10, 2022, 10:21:48 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Do not create all application forms at initialization phase but dynamically.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormRecords.pas

    r26 r28  
    1616    AModify: TAction;
    1717    ARemove: TAction;
    18     ListView1: TListView;
     18    ListViewRecords: TListView;
    1919    MenuItem1: TMenuItem;
    2020    MenuItem2: TMenuItem;
     
    2929    procedure ARemoveExecute(Sender: TObject);
    3030    procedure FormShow(Sender: TObject);
    31     procedure ListView1Data(Sender: TObject; Item: TListItem);
    32     procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
     31    procedure ListViewRecordsData(Sender: TObject; Item: TListItem);
     32    procedure ListViewRecordsSelectItem(Sender: TObject; Item: TListItem;
    3333      Selected: Boolean);
    3434  public
     
    3838  end;
    3939
    40 var
    41   FormRecords: TFormRecords;
    4240
    4341implementation
     
    6563end;
    6664
    67 procedure TFormRecords.ListView1Data(Sender: TObject; Item: TListItem);
     65procedure TFormRecords.ListViewRecordsData(Sender: TObject; Item: TListItem);
    6866var
    6967  I: Integer;
     
    7977end;
    8078
    81 procedure TFormRecords.ListView1SelectItem(Sender: TObject; Item: TListItem;
     79procedure TFormRecords.ListViewRecordsSelectItem(Sender: TObject; Item: TListItem;
    8280  Selected: Boolean);
    8381begin
     
    8785procedure TFormRecords.AModifyExecute(Sender: TObject);
    8886begin
    89   if Assigned(ListView1.Selected) then begin
    90     FormRecord.Table := Table;
    91     FormRecord.Load(TRecord(ListView1.Selected.Data));
    92     if FormRecord.ShowModal = mrOk then begin
    93       FormRecord.Save(TRecord(ListView1.Selected.Data));
    94       ReloadList;
     87  if Assigned(ListViewRecords.Selected) then begin
     88    with TFormRecord.Create(nil) do
     89    try
     90      Table := Self.Table;
     91      Load(TRecord(ListViewRecords.Selected.Data));
     92      if ShowModal = mrOk then begin
     93        Save(TRecord(ListViewRecords.Selected.Data));
     94        ReloadList;
     95      end;
     96    finally
     97      Free;
    9598    end;
    9699  end;
     
    99102procedure TFormRecords.ARemoveExecute(Sender: TObject);
    100103begin
    101   if Assigned(ListView1.Selected) then
     104  if Assigned(ListViewRecords.Selected) then
    102105  if MessageDlg(SRemoveRecord, SRemoveRecordConfirm,
    103106  mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
    104     Table.Records.Remove(ListView1.Selected.Data);
     107    Table.Records.Remove(ListViewRecords.Selected.Data);
    105108    ReloadList;
    106109  end;
     
    123126  end;
    124127
    125   FormRecord.Table := Table;
    126   FormRecord.Load(NewRecord);
    127   if FormRecord.ShowModal = mrOk then begin
    128     FormRecord.Save(NewRecord);
    129     Table.Records.Add(NewRecord);
    130     ReloadList;
    131   end else NewRecord.Free;
     128  with TFormRecord.Create(nil) do
     129  try
     130    Table := Self.Table;
     131    Load(NewRecord);
     132    if ShowModal = mrOk then begin
     133      Save(NewRecord);
     134      Table.Records.Add(NewRecord);
     135      ReloadList;
     136    end else NewRecord.Free;
     137  finally
     138    Free;
     139  end;
    132140end;
    133141
    134142procedure TFormRecords.UpdateInterface;
    135143begin
    136   AModify.Enabled := Assigned(ListView1.Selected);
    137   ARemove.Enabled := Assigned(ListView1.Selected);
     144  AModify.Enabled := Assigned(ListViewRecords.Selected);
     145  ARemove.Enabled := Assigned(ListViewRecords.Selected);
    138146end;
    139147
     
    144152  Table.LoadRecords;
    145153
    146   ListView1.Columns.BeginUpdate;
    147   while ListView1.Columns.Count > Table.Fields.Count do
    148     ListView1.Columns[ListView1.ColumnCount - 1].Free;
    149   while ListView1.Columns.Count < Table.Fields.Count do
    150     ListView1.Columns.Add;
     154  ListViewRecords.Columns.BeginUpdate;
     155  while ListViewRecords.Columns.Count > Table.Fields.Count do
     156    ListViewRecords.Columns[ListViewRecords.ColumnCount - 1].Free;
     157  while ListViewRecords.Columns.Count < Table.Fields.Count do
     158    ListViewRecords.Columns.Add;
    151159  for I := 0 to Table.Fields.Count - 1 do begin
    152     ListView1.Columns[I].Caption := TField(Table.Fields[I]).TextBefore;
    153     ListView1.Columns[I].Width := 200;
     160    ListViewRecords.Columns[I].Caption := TField(Table.Fields[I]).TextBefore;
     161    ListViewRecords.Columns[I].Width := 200;
    154162  end;
    155   ListView1.Columns.EndUpdate;
     163  ListViewRecords.Columns.EndUpdate;
    156164
    157   ListView1.Items.Count := Table.Records.Count;
    158   ListView1.Repaint;
     165  ListViewRecords.Items.Count := Table.Records.Count;
     166  ListViewRecords.Repaint;
    159167end;
    160168
Note: See TracChangeset for help on using the changeset viewer.