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

    r26 r28  
    1515    ButtonOk: TButton;
    1616    ButtonCancel: TButton;
    17     ComboBox1: TComboBox;
     17    ComboBoxDbEngines: TComboBox;
    1818    EditHost: TEdit;
    1919    EditXml: TEdit;
     
    3232    TabSheetSql: TTabSheet;
    3333    procedure ButtonXmlBrowseClick(Sender: TObject);
    34     procedure ComboBox1Change(Sender: TObject);
    35     procedure FormShow(Sender: TObject);
     34    procedure ComboBoxDbEnginesChange(Sender: TObject);
     35    procedure FormCreate(Sender: TObject);
    3636  public
    3737    procedure Load(ConnectProfile: TDbConnectProfile);
    3838    procedure Save(ConnectProfile: TDbConnectProfile);
    39     procedure Init;
     39    procedure ReloadDbEngines;
    4040    procedure UpdateInterface;
    4141  end;
    42 
    43 var
    44   FormConnect: TFormConnect;
    4542
    4643
     
    5249  UCore, UEngineXML, UEngineMySQL;
    5350
     51resourcestring
     52  SAnyFile = 'Any file';
     53  SXmlFiles = 'XML files';
     54
    5455{ TFormConnect }
    55 
    56 procedure TFormConnect.FormShow(Sender: TObject);
    57 begin
    58 end;
    5956
    6057procedure TFormConnect.ButtonXmlBrowseClick(Sender: TObject);
    6158begin
    62   OpenDialog1.Filter := 'XML files (.xml)|*.xml|Any file|*.*';
     59  OpenDialog1.Filter := SXmlFiles + ' (.xml)|*.xml|' + SAnyFile + '|*.*';
    6360  OpenDialog1.InitialDir := ExtractFileDir(EditXml.Text);
    6461  OpenDialog1.FileName := ExtractFileName(EditXml.Text);
     
    6764end;
    6865
    69 procedure TFormConnect.ComboBox1Change(Sender: TObject);
     66procedure TFormConnect.ComboBoxDbEnginesChange(Sender: TObject);
    7067begin
    7168  UpdateInterface;
     69end;
     70
     71procedure TFormConnect.FormCreate(Sender: TObject);
     72begin
     73  ReloadDbEngines;
    7274end;
    7375
     
    7678  EditName.Text := ConnectProfile.Name;
    7779  //EditConnectionString.Text := Database.ConnectionString;
    78   ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ConnectProfile.ClientType);
    79   if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
    80     ComboBox1.ItemIndex := 0;
     80  ComboBoxDbEngines.ItemIndex := ComboBoxDbEngines.Items.IndexOfObject(ConnectProfile.ClientType);
     81  if (ComboBoxDbEngines.ItemIndex = -1) and (ComboBoxDbEngines.Items.Count > 0) then
     82    ComboBoxDbEngines.ItemIndex := 0;
    8183  if ConnectProfile.Params is TDbConnectParamsXml then
    8284    EditXml.Text := TDbConnectParamsXml(ConnectProfile.Params).FileName;
     
    9294  ConnectProfile.Name := EditName.Text;
    9395  //DatabaseClient.ConnectionString := EditConnectionString.Text;
    94   ConnectProfile.ClientType := TDbClientType(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
     96  ConnectProfile.ClientType := TDbClientType(ComboBoxDbEngines.Items.Objects[ComboBoxDbEngines.ItemIndex]);
    9597  if ConnectProfile.Params is TDbConnectParamsXml then
    9698    TDbConnectParamsXml(ConnectProfile.Params).FileName := EditXml.Text;
     
    101103end;
    102104
    103 procedure TFormConnect.Init;
     105procedure TFormConnect.ReloadDbEngines;
    104106var
    105107  I: Integer;
    106108begin
    107   ComboBox1.Items.Clear;
    108   for I := 0 to Core.DbManager.ClientTypes.Count - 1 do
    109     ComboBox1.Items.AddObject(TDbClientType(Core.DbManager.ClientTypes[I]).Name,
    110       Core.DbManager.ClientTypes[I]);
     109  ComboBoxDbEngines.Items.BeginUpdate;
     110  try
     111    ComboBoxDbEngines.Items.Clear;
     112    for I := 0 to Core.DbManager.ClientTypes.Count - 1 do
     113      ComboBoxDbEngines.Items.AddObject(Core.DbManager.ClientTypes[I].Name,
     114        Core.DbManager.ClientTypes[I]);
     115  finally
     116    ComboBoxDbEngines.Items.Endupdate;
     117  end;
    111118end;
    112119
    113120procedure TFormConnect.UpdateInterface;
    114121begin
    115   PageControl1.TabIndex := ComboBox1.ItemIndex;
     122  PageControl1.TabIndex := ComboBoxDbEngines.ItemIndex;
    116123end;
    117124
Note: See TracChangeset for help on using the changeset viewer.