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/UFormFields.pas

    r26 r28  
    4545  end;
    4646
    47 var
    48   FormFields: TFormFields;
    49 
    5047implementation
    5148
     
    8481  if Fields.Table.DbClient.ConnectProfile.ClientType.DataTypes.Count > 0 then
    8582    NewField.DataType := TDataType(Fields.Table.DbClient.ConnectProfile.ClientType.DataTypes[0]);
    86   FormField.Load(NewField);
    87   if FormField.ShowModal = mrOk then begin
    88     FormField.Save(NewField);
    89     Fields.Table.DbClient.Query('INSERT INTO ModelField ( Name , Caption , Model , DataType ) VALUES ( ' +
    90       NewField.Name + ' , ' + NewField.TextBefore + ' , ' + TableName + ' , ' + NewField.DataType.Name + ' )');
    91     ReloadList;
    92   end else NewField.Free;
     83  with TFormField.Create(nil) do
     84  try
     85    Load(NewField);
     86    if ShowModal = mrOk then begin
     87      Save(NewField);
     88      Fields.Table.DbClient.Query('INSERT INTO ModelField ( Name , Caption , Model , DataType ) VALUES ( ' +
     89        NewField.Name + ' , ' + NewField.TextBefore + ' , ' + TableName + ' , ' + NewField.DataType.Name + ' )');
     90      ReloadList;
     91    end else NewField.Free;
     92  finally
     93    Free;
     94  end;
    9395end;
    9496
     
    101103begin
    102104  if Assigned(ListView1.Selected) then begin
    103     FormField.Load(TField(ListView1.Selected.Data));
    104     if FormField.ShowModal = mrOk then begin
    105       FormField.Save(TField(ListView1.Selected.Data));
    106       Fields.Table.DbClient.Query('UPDATE ModelField SET Caption = ' + TField(ListView1.Selected.Data).TextBefore +
    107         ' , DataType = ' + TField(ListView1.Selected.Data).DataType.Name +
    108         ' WHERE Model = ' + Fields.Table.Name +' , Name = ' + TField(ListView1.Selected.Data).Name);
    109       ReloadList;
     105    with TFormField.Create(nil) do
     106    try
     107      Load(TField(ListView1.Selected.Data));
     108      if ShowModal = mrOk then begin
     109        Save(TField(ListView1.Selected.Data));
     110        Fields.Table.DbClient.Query('UPDATE ModelField SET Caption = ' + TField(ListView1.Selected.Data).TextBefore +
     111          ' , DataType = ' + TField(ListView1.Selected.Data).DataType.Name +
     112          ' WHERE Model = ' + Fields.Table.Name +' , Name = ' + TField(ListView1.Selected.Data).Name);
     113        ReloadList;
     114      end;
     115    finally
     116      Free;
    110117    end;
    111118  end;
     
    160167  Fields.Clear;
    161168  DbRows := TDbRows.Create;
    162   Fields.Table.DbClient.Query('SELECT * FROM ModelField WHERE Model = ' + Fields.Table.Name, DbRows);
    163   for I := 0 to DbRows.Count - 1 do begin
    164     NewField := Fields.AddNew(DbRows[I].Items['Name'],
    165       Fields.Table.DbClient.DbManager.DataTypes.SearchByName(DbRows[I].Items['DataType']));
    166     NewField.TextBefore := DbRows[I].Items['Caption'];
     169  try
     170    Fields.Table.DbClient.Query('SELECT * FROM ModelField WHERE Model = ' + Fields.Table.Name, DbRows);
     171    for I := 0 to DbRows.Count - 1 do begin
     172      NewField := Fields.AddNew(DbRows[I].Items['Name'],
     173        Fields.Table.DbClient.DbManager.DataTypes.SearchByName(DbRows[I].Items['DataType']));
     174      NewField.TextBefore := DbRows[I].Items['Caption'];
     175    end;
     176  finally
     177    DbRows.Free;
    167178  end;
    168   DbRows.Free;
    169179
    170180  ListView1.Items.Count := Fields.Count;
Note: See TracChangeset for help on using the changeset viewer.