Changeset 28


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.
Location:
trunk
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/DbEngines/UEngineXML.pas

    r26 r28  
    3737    function TableCreateIfNotExists(Name: string): TTable;
    3838    function FieldCreateIfNotExists(TableName, FieldName: string; DataType: TDataType): TField;
    39   protected
    4039  public
    4140    procedure Query(Text: string; DbRows: TDbRows = nil); override;
     
    101100  Row.Values.Count := Row.Parent.Fields.Count;
    102101  for I := 0 to Row.Values.Count - 1 do
    103     Row.Values[I] := TValueClass(TField(Row.Parent.Fields[I]).GetValueClass).Create;
     102    Row.Values[I] := TValueClass(Row.Parent.Fields[I].GetValueClass).Create;
    104103
    105104  Node2 := Node.FirstChild;
    106105  I := 0;
    107106  while Assigned(Node2) and (Node2.NodeName = 'Value') and (I < Row.Values.Count) do begin
    108     case TField(Row.Parent.Fields[I]).DataType.FieldType of
     107    case Row.Parent.Fields[I].DataType.FieldType of
    109108      ftString: TValueString(Row.Values[I]).Value := string(Node2.TextContent);
    110109      ftInteger: TValueInteger(Row.Values[I]).Value := StrToInt(string(Node2.TextContent));
     
    126125    NewNode := Node.OwnerDocument.CreateElement('Value');
    127126    Node.AppendChild(NewNode);
    128     case TField(Row.Parent.Fields[I]).DataType.FieldType of
     127    case Row.Parent.Fields[I].DataType.FieldType of
    129128      ftString: NewNode.TextContent := UnicodeString(TValueString(Row.Values[I]).Value);
    130129      ftInteger: NewNode.TextContent := UnicodeString(IntToStr(TValueInteger(Row.Values[I]).Value));
     
    160159    NewNode := Node.OwnerDocument.CreateElement('Record');
    161160    Node.AppendChild(NewNode);
    162     SaveNodeRecord(TRecord(Records.Items[I]), NewNode);
     161    SaveNodeRecord(Records[I], NewNode);
    163162  end;
    164163end;
     
    204203    NewNode := Node.OwnerDocument.CreateElement('Field');
    205204    Node.AppendChild(NewNode);
    206     SaveNodeField(TField(Fields.Items[I]), NewNode);
     205    SaveNodeField(Fields[I], NewNode);
    207206  end;
    208207end;
     
    264263    NewNode := Node.OwnerDocument.CreateElement('Table');
    265264    Node.AppendChild(NewNode);
    266     SaveNodeTable(TTable(Tables.Items[I]), NewNode);
     265    SaveNodeTable(Tables[I], NewNode);
    267266  end;
    268267end;
     
    647646  if FileExists(FileName) then
    648647    LoadFromFile(FileName);
    649   (*
     648
     649(*
    650650  TableCreateIfNotExists('Model');
    651651  TableCreateIfNotExists('ModelField');
     
    677677begin
    678678  Tables := TTables.Create;
    679   inherited Create;
     679  inherited;
    680680end;
    681681
    682682destructor TDatabaseXML.Destroy;
    683683begin
    684   Tables.Free;
    685   inherited Destroy;
    686 end;
    687 
     684  FreeAndNil(Tables);
     685  inherited;
     686end;
    688687
    689688end.
  • trunk/Forms/UFormConnect.lfm

    r27 r28  
    44  Top = 509
    55  Width = 739
    6   Caption = 'Connection parameters:'
     6  Caption = 'Connection parameters'
    77  ClientHeight = 542
    88  ClientWidth = 739
    99  DesignTimePPI = 144
    10   OnShow = FormShow
     10  OnCreate = FormCreate
    1111  LCLVersion = '2.2.2.0'
    1212  object EditName: TEdit
    13     Left = 253
     13    Left = 256
    1414    Height = 43
    1515    Top = 25
    16     Width = 313
     16    Width = 310
    1717    TabOrder = 0
    1818  end
    1919  object Label1: TLabel
    20     Left = 19
     20    Left = 18
    2121    Height = 26
    22     Top = 31
     22    Top = 32
    2323    Width = 56
    2424    Caption = 'Name:'
     
    2626  end
    2727  object Label2: TLabel
    28     Left = 19
     28    Left = 18
    2929    Height = 26
    3030    Top = 80
     
    3333    ParentColor = False
    3434  end
    35   object ComboBox1: TComboBox
     35  object ComboBoxDbEngines: TComboBox
    3636    Left = 256
    3737    Height = 42
    38     Top = 80
    39     Width = 312
     38    Top = 72
     39    Width = 310
    4040    ItemHeight = 0
    41     OnChange = ComboBox1Change
     41    OnChange = ComboBoxDbEnginesChange
    4242    Style = csDropDownList
    4343    TabOrder = 1
    4444  end
    4545  object ButtonOk: TButton
    46     Left = 552
     46    Left = 624
    4747    Height = 30
    48     Top = 482
     48    Top = 496
    4949    Width = 90
    5050    Anchors = [akRight, akBottom]
     
    5454  end
    5555  object ButtonCancel: TButton
    56     Left = 403
     56    Left = 488
    5757    Height = 30
    58     Top = 480
     58    Top = 496
    5959    Width = 90
    6060    Anchors = [akRight, akBottom]
     
    6565  object PageControl1: TPageControl
    6666    Left = 18
    67     Height = 300
     67    Height = 340
    6868    Top = 139
    6969    Width = 703
     
    7474    TabOrder = 4
    7575    object TabSheetXml: TTabSheet
    76       ClientHeight = 296
     76      ClientHeight = 336
    7777      ClientWidth = 693
    7878      object Label3: TLabel
     
    104104    end
    105105    object TabSheetSql: TTabSheet
    106       ClientHeight = 296
     106      ClientHeight = 336
    107107      ClientWidth = 693
    108108      object Label4: TLabel
  • trunk/Forms/UFormConnect.lrj

    r27 r28  
    11{"version":1,"strings":[
    2 {"hash":117590810,"name":"tformconnect.caption","sourcebytes":[67,111,110,110,101,99,116,105,111,110,32,112,97,114,97,109,101,116,101,114,115,58],"value":"Connection parameters:"},
     2{"hash":124789939,"name":"tformconnect.caption","sourcebytes":[67,111,110,110,101,99,116,105,111,110,32,112,97,114,97,109,101,116,101,114,115],"value":"Connection parameters"},
    33{"hash":5538698,"name":"tformconnect.label1.caption","sourcebytes":[78,97,109,101,58],"value":"Name:"},
    44{"hash":230808394,"name":"tformconnect.label2.caption","sourcebytes":[68,97,116,97,98,97,115,101,32,101,110,103,105,110,101,58],"value":"Database engine:"},
  • 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
  • trunk/Forms/UFormDatabases.pas

    r26 r28  
    4343  end;
    4444
    45 var
    46   FormDatabases: TFormDatabases;
    4745
    4846implementation
     
    5250uses
    5351  UCore, UFormConnect;
     52
     53resourcestring
     54  SRemoveDatabaseConnection = 'Remove database connection';
     55  SRemoveDatabaseConnectionQuery = 'Do you want to really remove database connection %s?';
     56  SNewDatabase = 'New database';
    5457
    5558{ TFormDatabases }
     
    7174begin
    7275  if Assigned(ListView1.Selected) then begin
    73     if MessageDlg('Remove database connection', 'Do you want to really remove database connection ' +
    74     TDbConnectProfile(ListView1.Selected.Data).Name, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
     76    if MessageDlg(SRemoveDatabaseConnection, Format(SRemoveDatabaseConnectionQuery, [
     77    TDbConnectProfile(ListView1.Selected.Data).Name]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
    7578      Core.DbManager.ConnectProfiles.Remove(ListView1.Selected.Data);
    7679      ReloadList;
     
    8487begin
    8588  NewConnectProfile := TDbConnectProfile.Create;
    86   NewConnectProfile.Name := 'New database';
    87   FormConnect.Load(NewConnectProfile);
    88   if FormConnect.ShowModal = mrOk then begin
    89     FormConnect.Save(NewConnectProfile);
    90     Core.DbManager.ConnectProfiles.Add(NewConnectProfile);
    91     ReloadList;
    92   end else NewConnectProfile.Free;
     89  NewConnectProfile.Name := SNewDatabase;
     90  with TFormConnect.Create(nil) do
     91  try
     92    Load(NewConnectProfile);
     93    if ShowModal = mrOk then begin
     94      Save(NewConnectProfile);
     95      Core.DbManager.ConnectProfiles.Add(NewConnectProfile);
     96      ReloadList;
     97    end else NewConnectProfile.Free;
     98  finally
     99    Free;
     100  end;
    93101end;
    94102
     
    96104begin
    97105  if Assigned(ListView1.Selected) then begin
    98     FormConnect.Load(TDbConnectProfile(ListView1.Selected.Data));
    99     if FormConnect.ShowModal = mrOk then begin
    100       FormConnect.Save(TDbConnectProfile(ListView1.Selected.Data));
    101       ReloadList;
     106    with TFormConnect.Create(nil) do
     107    try
     108      Load(TDbConnectProfile(ListView1.Selected.Data));
     109      if ShowModal = mrOk then begin
     110        Save(TDbConnectProfile(ListView1.Selected.Data));
     111        ReloadList;
     112      end;
     113    finally
     114      Free;
    102115    end;
    103116  end;
  • trunk/Forms/UFormField.lfm

    r20 r28  
    11object FormField: TFormField
    22  Left = 721
    3   Height = 444
     3  Height = 533
    44  Top = 85
    5   Width = 974
     5  Width = 1169
    66  Caption = 'Field'
    7   ClientHeight = 444
    8   ClientWidth = 974
    9   DesignTimePPI = 120
     7  ClientHeight = 533
     8  ClientWidth = 1169
     9  DesignTimePPI = 144
    1010  OnCreate = FormCreate
    1111  OnShow = FormShow
    1212  Position = poMainFormCenter
    13   LCLVersion = '1.8.0.6'
     13  LCLVersion = '2.2.2.0'
    1414  object EditName: TEdit
    15     Left = 168
    16     Height = 28
    17     Top = 11
    18     Width = 264
     15    Left = 202
     16    Height = 43
     17    Top = 13
     18    Width = 317
    1919    TabOrder = 0
    2020  end
    2121  object Label1: TLabel
    22     Left = 17
    23     Height = 20
    24     Top = 21
    25     Width = 43
     22    Left = 20
     23    Height = 26
     24    Top = 25
     25    Width = 56
    2626    Caption = 'Name:'
    2727    ParentColor = False
    2828  end
    2929  object ButtonOk: TButton
    30     Left = 880
    31     Height = 25
    32     Top = 400
    33     Width = 75
     30    Left = 1056
     31    Height = 30
     32    Top = 480
     33    Width = 90
    3434    Anchors = [akRight, akBottom]
    3535    Caption = 'Ok'
     
    3838  end
    3939  object EditTextBefore: TEdit
    40     Left = 167
    41     Height = 28
    42     Top = 88
    43     Width = 265
     40    Left = 200
     41    Height = 43
     42    Top = 106
     43    Width = 318
    4444    TabOrder = 2
    4545  end
    4646  object Label2: TLabel
    47     Left = 16
    48     Height = 20
    49     Top = 98
    50     Width = 79
     47    Left = 19
     48    Height = 26
     49    Top = 118
     50    Width = 100
    5151    Caption = 'Text before:'
    5252    ParentColor = False
    5353  end
    5454  object EditTextAfter: TEdit
    55     Left = 167
    56     Height = 28
    57     Top = 136
    58     Width = 265
     55    Left = 200
     56    Height = 43
     57    Top = 163
     58    Width = 318
    5959    TabOrder = 3
    6060  end
    6161  object Label3: TLabel
    62     Left = 16
    63     Height = 20
    64     Top = 144
    65     Width = 66
     62    Left = 19
     63    Height = 26
     64    Top = 173
     65    Width = 84
    6666    Caption = 'Text after:'
    6767    ParentColor = False
    6868  end
    6969  object Label4: TLabel
    70     Left = 17
    71     Height = 20
    72     Top = 56
    73     Width = 68
     70    Left = 20
     71    Height = 26
     72    Top = 67
     73    Width = 85
    7474    Caption = 'Data type:'
    7575    ParentColor = False
    7676  end
    7777  object ComboBoxType: TComboBox
    78     Left = 167
    79     Height = 28
    80     Top = 48
    81     Width = 265
    82     ItemHeight = 20
     78    Left = 200
     79    Height = 42
     80    Top = 58
     81    Width = 318
     82    ItemHeight = 0
    8383    OnChange = ComboBoxTypeChange
    8484    Style = csDropDownList
     
    8686  end
    8787  object ButtonCancel: TButton
    88     Left = 784
    89     Height = 25
    90     Top = 400
    91     Width = 75
     88    Left = 941
     89    Height = 30
     90    Top = 480
     91    Width = 90
    9292    Anchors = [akRight, akBottom]
    9393    Caption = 'Cancel'
     
    9696  end
    9797  object PageControl1: TPageControl
    98     Left = 16
    99     Height = 200
    100     Top = 184
    101     Width = 936
     98    Left = 19
     99    Height = 240
     100    Top = 221
     101    Width = 1124
    102102    ActivePage = TabSheetBoolean
    103103    Anchors = [akTop, akLeft, akRight, akBottom]
     
    106106    TabOrder = 6
    107107    object TabSheetString: TTabSheet
    108       ClientHeight = 194
    109       ClientWidth = 930
     108      ClientHeight = 236
     109      ClientWidth = 1114
    110110      object EditStringDefault: TEdit
    111         Left = 160
    112         Height = 36
    113         Top = 8
    114         Width = 265
     111        Left = 192
     112        Height = 43
     113        Top = 10
     114        Width = 318
    115115        TabOrder = 0
    116116      end
    117117      object Label5: TLabel
    118         Left = 16
    119         Height = 26
    120         Top = 8
    121         Width = 117
     118        Left = 19
     119        Height = 26
     120        Top = 10
     121        Width = 116
    122122        Caption = 'Default value:'
    123123        ParentColor = False
     
    125125    end
    126126    object TabSheetInteger: TTabSheet
    127       ClientHeight = 194
    128       ClientWidth = 930
     127      ClientHeight = 236
     128      ClientWidth = 1114
    129129      object Label10: TLabel
    130         Left = 12
    131         Height = 26
    132         Top = 21
     130        Left = 14
     131        Height = 26
     132        Top = 25
    133133        Width = 87
    134134        Caption = 'Minimum:'
     
    136136      end
    137137      object SpinEditMin: TSpinEdit
    138         Left = 153
    139         Height = 36
    140         Top = 19
    141         Width = 255
     138        Left = 184
     139        Height = 43
     140        Top = 23
     141        Width = 306
    142142        MaxValue = 10000000
    143143        TabOrder = 0
    144144      end
    145145      object SpinEditMax: TSpinEdit
    146         Left = 153
    147         Height = 36
    148         Top = 56
    149         Width = 255
     146        Left = 184
     147        Height = 43
     148        Top = 67
     149        Width = 306
    150150        TabOrder = 1
    151151      end
    152152      object Label11: TLabel
    153         Left = 12
    154         Height = 26
    155         Top = 58
     153        Left = 14
     154        Height = 26
     155        Top = 70
    156156        Width = 91
    157157        Caption = 'Maximum:'
     
    160160    end
    161161    object TabSheetDateTime: TTabSheet
    162       ClientHeight = 194
    163       ClientWidth = 930
     162      ClientHeight = 236
     163      ClientWidth = 1114
    164164      object DateEditMin: TDateEdit
    165         Left = 136
    166         Height = 36
    167         Top = 24
    168         Width = 216
     165        Left = 163
     166        Height = 43
     167        Top = 29
     168        Width = 259
    169169        CalendarDisplaySettings = [dsShowHeadings, dsShowDayNames]
    170170        DateOrder = doNone
    171         ButtonWidth = 23
     171        ButtonWidth = 28
    172172        NumGlyphs = 1
    173173        MaxLength = 0
     
    175175      end
    176176      object Label6: TLabel
    177         Left = 16
    178         Height = 26
    179         Top = 32
     177        Left = 19
     178        Height = 26
     179        Top = 38
    180180        Width = 87
    181181        Caption = 'Minimum:'
     
    183183      end
    184184      object DateEditMax: TDateEdit
    185         Left = 136
    186         Height = 36
    187         Top = 72
    188         Width = 216
     185        Left = 163
     186        Height = 43
     187        Top = 86
     188        Width = 259
    189189        CalendarDisplaySettings = [dsShowHeadings, dsShowDayNames]
    190190        DateOrder = doNone
    191         ButtonWidth = 23
     191        ButtonWidth = 28
    192192        NumGlyphs = 1
    193193        MaxLength = 0
     
    195195      end
    196196      object Label7: TLabel
    197         Left = 16
    198         Height = 26
    199         Top = 80
     197        Left = 19
     198        Height = 26
     199        Top = 96
    200200        Width = 91
    201201        Caption = 'Maximum:'
     
    206206    end
    207207    object TabSheetFloat: TTabSheet
    208       ClientHeight = 194
    209       ClientWidth = 930
     208      ClientHeight = 236
     209      ClientWidth = 1114
    210210      object FloatSpinEditMin: TFloatSpinEdit
    211         Left = 144
    212         Height = 36
    213         Top = 16
    214         Width = 266
    215         Increment = 1
     211        Left = 173
     212        Height = 43
     213        Top = 19
     214        Width = 319
    216215        MaxValue = 100000000
    217         MinValue = 0
    218         TabOrder = 0
    219         Value = 0
     216        TabOrder = 0
    220217      end
    221218      object Label8: TLabel
    222         Left = 8
    223         Height = 26
    224         Top = 25
     219        Left = 10
     220        Height = 26
     221        Top = 30
    225222        Width = 87
    226223        Caption = 'Minimum:'
     
    228225      end
    229226      object FloatSpinEditMax: TFloatSpinEdit
    230         Left = 144
    231         Height = 36
    232         Top = 64
    233         Width = 266
    234         Increment = 1
     227        Left = 173
     228        Height = 43
     229        Top = 77
     230        Width = 319
    235231        MaxValue = 100
    236         MinValue = 0
    237232        TabOrder = 1
    238         Value = 0
    239233      end
    240234      object Label9: TLabel
    241         Left = 8
    242         Height = 26
    243         Top = 73
     235        Left = 10
     236        Height = 26
     237        Top = 88
    244238        Width = 91
    245239        Caption = 'Maximum:'
  • trunk/Forms/UFormField.pas

    r26 r28  
    4949    procedure Save(Field: TField);
    5050  end;
    51 
    52 var
    53   FormField: TFormField;
    5451
    5552
  • 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;
  • trunk/Forms/UFormMain.lfm

    r27 r28  
    11object FormMain: TFormMain
    2   Left = 449
    3   Height = 1274
    4   Top = 108
    5   Width = 1875
     2  Left = 403
     3  Height = 669
     4  Top = 365
     5  Width = 1088
    66  Caption = 'MyData'
    7   ClientHeight = 1240
    8   ClientWidth = 1875
     7  ClientHeight = 635
     8  ClientWidth = 1088
    99  DesignTimePPI = 144
    1010  Menu = MainMenu1
    1111  OnActivate = FormActivate
    1212  OnClose = FormClose
     13  OnCreate = FormCreate
     14  OnDestroy = FormDestroy
    1315  OnShow = FormShow
    1416  LCLVersion = '2.2.2.0'
     
    1719    Left = 0
    1820    Height = 28
    19     Top = 1212
    20     Width = 1875
     21    Top = 607
     22    Width = 1088
    2123    Panels = <>
    2224  end
     
    2527    Height = 44
    2628    Top = 0
    27     Width = 1875
     29    Width = 1088
    2830    AutoSize = True
    2931    Bands = <   
     
    7072  object MainMenu1: TMainMenu
    7173    Images = Core.ImageList1
    72     Left = 1236
    73     Top = 324
     74    Left = 112
     75    Top = 112
    7476    object MenuItem1: TMenuItem
    7577      Caption = 'Database'
  • trunk/Forms/UFormMain.pas

    r27 r28  
    55uses
    66  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
    7   ComCtrls;
     7  ComCtrls, UFormTables;
    88
    99type
     
    3030    procedure FormActivate(Sender: TObject);
    3131    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     32    procedure FormCreate(Sender: TObject);
     33    procedure FormDestroy(Sender: TObject);
    3234    procedure FormShow(Sender: TObject);
    3335  private
    3436    procedure SetToolbarHints;
    3537  public
     38    FormTables: TFormTables;
    3639    procedure DockInit;
    3740    procedure UpdateInterface;
     
    4750
    4851uses
    49   UCore, UFormTables;
     52  UCore;
    5053
    5154{ TFormMain }
     
    6265  Core.Done;
    6366  Core.PersistentForm1.Save(Self);
     67end;
     68
     69procedure TFormMain.FormCreate(Sender: TObject);
     70begin
     71  FormTables := TFormTables.Create(nil);
     72end;
     73
     74procedure TFormMain.FormDestroy(Sender: TObject);
     75begin
     76  FreeAndNil(FormTables);
    6477end;
    6578
     
    8699    NewCaption := Core.DbClient.ConnectProfile.Name + ' - ' + NewCaption;
    87100  FormMain.Caption := NewCaption;
     101  FormTables.UpdateInterface;
    88102end;
    89103
  • trunk/Forms/UFormPreferences.pas

    r26 r28  
    2323  end;
    2424
    25 var
    26   FormPreferences: TFormPreferences;
    2725
    2826implementation
  • trunk/Forms/UFormRecord.pas

    r26 r28  
    55uses
    66  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    7   ComCtrls, ActnList, StdCtrls, EditBtn, UDatabase, Contnrs, Spin;
     7  ComCtrls, ActnList, StdCtrls, EditBtn, UDatabase, Spin, Generics.Collections;
    88
    99type
     
    2626    Table: TTable;
    2727    Row: TRecord;
    28     Controls: TObjectList; // TListObject<TControl>
    29     Labels: TObjectList; // TListObject<TControl>
     28    Controls: TObjectList<TControl>;
     29    Labels: TObjectList<TControl>;
    3030    procedure ReloadControls;
    3131    procedure Load(DataRecord: TRecord);
     
    3333  end;
    3434
    35 var
    36   FormRecord: TFormRecord;
    3735
    3836implementation
     
    4341{$R *.lfm}
    4442
     43resourcestring
     44  STableRecordEdit = 'Table record edit';
     45
    4546{ TFormRecord }
    4647
    4748procedure TFormRecord.FormShow(Sender: TObject);
    4849begin
    49   Caption := 'Table record edit - ' + Table.Caption;
     50  Caption := STableRecordEdit + ' - ' + Table.Caption;
    5051  ReloadControls;
    5152end;
     
    6364procedure TFormRecord.FormCreate(Sender: TObject);
    6465begin
    65   Controls := TObjectList.Create;
    66   Labels := TObjectList.Create;
     66  Controls := TObjectList<TControl>.Create;
     67  Labels := TObjectList<TControl>.Create;
    6768end;
    6869
    6970procedure TFormRecord.FormDestroy(Sender: TObject);
    7071begin
    71   Labels.Free;
    72   Controls.Free;
     72  FreeAndNil(Labels);
     73  FreeAndNil(Controls);
    7374end;
    7475
  • trunk/Forms/UFormRecords.lfm

    r15 r28  
    11object FormRecords: TFormRecords
    22  Left = 621
    3   Height = 549
     3  Height = 824
    44  Top = 308
    5   Width = 897
     5  Width = 1346
    66  Caption = 'Records'
    7   ClientHeight = 549
    8   ClientWidth = 897
     7  ClientHeight = 824
     8  ClientWidth = 1346
     9  DesignTimePPI = 144
    910  OnShow = FormShow
    1011  Position = poMainFormCenter
    11   LCLVersion = '1.8.0.4'
    12   object ListView1: TListView
    13     Left = 4
    14     Height = 505
    15     Top = 4
    16     Width = 889
     12  LCLVersion = '2.2.2.0'
     13  object ListViewRecords: TListView
     14    Left = 6
     15    Height = 758
     16    Top = 6
     17    Width = 1334
    1718    Align = alClient
    18     BorderSpacing.Around = 4
     19    BorderSpacing.Around = 6
    1920    Columns = <   
    2021      item
    2122        Caption = 'Name'
    22         Width = 500
     23        Width = 750
    2324      end   
    2425      item
    2526        Caption = 'Records'
    26         Width = 453
     27        Width = 680
    2728      end>
    2829    OwnerData = True
     
    3233    TabOrder = 0
    3334    ViewStyle = vsReport
    34     OnData = ListView1Data
     35    OnData = ListViewRecordsData
    3536    OnDblClick = AModifyExecute
    36     OnSelectItem = ListView1SelectItem
     37    OnSelectItem = ListViewRecordsSelectItem
    3738  end
    3839  object ToolBar1: TToolBar
    3940    Left = 0
    40     Height = 36
    41     Top = 513
    42     Width = 897
     41    Height = 54
     42    Top = 770
     43    Width = 1346
    4344    Align = alBottom
    44     ButtonHeight = 32
    45     ButtonWidth = 32
     45    ButtonHeight = 48
     46    ButtonWidth = 48
    4647    Images = Core.ImageList1
    4748    ParentShowHint = False
     
    5455    end
    5556    object ToolButton2: TToolButton
    56       Left = 37
     57      Left = 49
    5758      Top = 2
    5859      Action = AModify
    5960    end
    6061    object ToolButton3: TToolButton
    61       Left = 73
     62      Left = 97
    6263      Top = 2
    6364      Action = ARemove
     
    6667  object ActionList1: TActionList
    6768    Images = Core.ImageList1
    68     left = 350
    69     top = 168
     69    Left = 525
     70    Top = 252
    7071    object AAdd: TAction
    7172      Caption = 'Add'
     
    8687  object PopupMenu1: TPopupMenu
    8788    Images = Core.ImageList1
    88     left = 492
    89     top = 172
     89    Left = 738
     90    Top = 258
    9091    object MenuItem1: TMenuItem
    9192      Action = AAdd
  • trunk/Forms/UFormRecords.lrj

    r26 r28  
    11{"version":1,"strings":[
    22{"hash":146434275,"name":"tformrecords.caption","sourcebytes":[82,101,99,111,114,100,115],"value":"Records"},
    3 {"hash":346165,"name":"tformrecords.listview1.columns[0].caption","sourcebytes":[78,97,109,101],"value":"Name"},
    4 {"hash":146434275,"name":"tformrecords.listview1.columns[1].caption","sourcebytes":[82,101,99,111,114,100,115],"value":"Records"},
     3{"hash":346165,"name":"tformrecords.listviewrecords.columns[0].caption","sourcebytes":[78,97,109,101],"value":"Name"},
     4{"hash":146434275,"name":"tformrecords.listviewrecords.columns[1].caption","sourcebytes":[82,101,99,111,114,100,115],"value":"Records"},
    55{"hash":18340,"name":"tformrecords.aadd.caption","sourcebytes":[65,100,100],"value":"Add"},
    66{"hash":88453081,"name":"tformrecords.amodify.caption","sourcebytes":[77,111,100,105,102,121],"value":"Modify"},
  • 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
  • trunk/Forms/UFormTable.lfm

    r5 r28  
    11object FormTable: TFormTable
    22  Left = 812
    3   Height = 351
     3  Height = 526
    44  Top = 164
    5   Width = 725
     5  Width = 665
    66  Caption = 'Table'
    7   ClientHeight = 351
    8   ClientWidth = 725
     7  ClientHeight = 526
     8  ClientWidth = 665
     9  DesignTimePPI = 144
    910  Position = poMainFormCenter
    10   LCLVersion = '1.3'
     11  LCLVersion = '2.2.2.0'
    1112  object EditName: TEdit
    12     Left = 168
    13     Height = 35
    14     Top = 11
    15     Width = 156
     13    Left = 250
     14    Height = 43
     15    Top = 24
     16    Width = 234
    1617    TabOrder = 0
    1718  end
    1819  object Label1: TLabel
    19     Left = 17
    20     Height = 25
    21     Top = 21
    22     Width = 131
     20    Left = 24
     21    Height = 26
     22    Top = 32
     23    Width = 119
    2324    Caption = 'System name:'
    2425    ParentColor = False
    2526  end
    2627  object ButtonOk: TButton
    27     Left = 572
    28     Height = 25
    29     Top = 302
    30     Width = 75
     28    Left = 436
     29    Height = 38
     30    Top = 452
     31    Width = 112
    3132    Anchors = [akRight, akBottom]
    3233    Caption = 'Ok'
     
    3536  end
    3637  object EditCaption: TEdit
    37     Left = 167
    38     Height = 35
    39     Top = 56
    40     Width = 156
     38    Left = 250
     39    Height = 43
     40    Top = 84
     41    Width = 234
    4142    TabOrder = 2
    4243  end
    4344  object Label2: TLabel
    44     Left = 16
    45     Height = 25
    46     Top = 66
    47     Width = 78
     45    Left = 24
     46    Height = 26
     47    Top = 96
     48    Width = 70
    4849    Caption = 'Caption:'
    4950    ParentColor = False
    5051  end
    5152  object ButtonCancel: TButton
    52     Left = 472
    53     Height = 25
    54     Top = 302
    55     Width = 75
     53    Left = 286
     54    Height = 38
     55    Top = 452
     56    Width = 112
    5657    Anchors = [akRight, akBottom]
    5758    Caption = 'Cancel'
  • trunk/Forms/UFormTable.pas

    r26 r28  
    2323  end;
    2424
    25 var
    26   FormTable: TFormTable;
    27 
    2825
    2926implementation
  • trunk/Forms/UFormTables.lfm

    r26 r28  
    1212  OnShow = FormShow
    1313  LCLVersion = '2.2.2.0'
    14   object ListView1: TListView
     14  object ListViewTables: TListView
    1515    Left = 5
    1616    Height = 739
     
    3434    TabOrder = 0
    3535    ViewStyle = vsReport
    36     OnData = ListView1Data
     36    OnData = ListViewTablesData
    3737    OnDblClick = AShowRecordsExecute
    38     OnSelectItem = ListView1SelectItem
     38    OnSelectItem = ListViewTablesSelectItem
    3939  end
    4040  object ToolBar1: TToolBar
  • trunk/Forms/UFormTables.lrj

    r26 r28  
    11{"version":1,"strings":[
    22{"hash":94868163,"name":"tformtables.caption","sourcebytes":[84,97,98,108,101,115],"value":"Tables"},
    3 {"hash":346165,"name":"tformtables.listview1.columns[0].caption","sourcebytes":[78,97,109,101],"value":"Name"},
    4 {"hash":146434275,"name":"tformtables.listview1.columns[1].caption","sourcebytes":[82,101,99,111,114,100,115],"value":"Records"},
     3{"hash":346165,"name":"tformtables.listviewtables.columns[0].caption","sourcebytes":[78,97,109,101],"value":"Name"},
     4{"hash":146434275,"name":"tformtables.listviewtables.columns[1].caption","sourcebytes":[82,101,99,111,114,100,115],"value":"Records"},
    55{"hash":18340,"name":"tformtables.aadd.caption","sourcebytes":[65,100,100],"value":"Add"},
    66{"hash":88453081,"name":"tformtables.amodify.caption","sourcebytes":[77,111,100,105,102,121],"value":"Modify"},
  • trunk/Forms/UFormTables.pas

    r26 r28  
    1818    ARemove: TAction;
    1919    ActionList1: TActionList;
    20     ListView1: TListView;
     20    ListViewTables: TListView;
    2121    MenuItem1: TMenuItem;
    2222    MenuItem2: TMenuItem;
     
    3939    procedure FormDestroy(Sender: TObject);
    4040    procedure FormShow(Sender: TObject);
    41     procedure ListView1Data(Sender: TObject; Item: TListItem);
    42     procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
     41    procedure ListViewTablesData(Sender: TObject; Item: TListItem);
     42    procedure ListViewTablesSelectItem(Sender: TObject; Item: TListItem;
    4343      Selected: Boolean);
    4444  private
     
    5353  end;
    5454
    55 var
    56   FormTables: TFormTables;
    57 
    5855
    5956implementation
     
    7168{ TFormTables }
    7269
    73 procedure TFormTables.ListView1Data(Sender: TObject; Item: TListItem);
     70procedure TFormTables.ListViewTablesData(Sender: TObject; Item: TListItem);
    7471begin
    7572  if (Item.Index >= 0) and (Item.Index < FTables.Count) then
    7673  with TTable(FTables[Item.Index]) do begin
    7774    Item.Caption := Caption;
    78     Item.SubItems.Add(IntToStr(RecordsCount));
     75    Item.SubItems.Add(IntToStr(RecordsCount) + ' ' + IntToStr(Fields.Count));
    7976    Item.Data := FTables[Item.Index];
    8077  end
    8178end;
    8279
    83 procedure TFormTables.ListView1SelectItem(Sender: TObject; Item: TListItem;
     80procedure TFormTables.ListViewTablesSelectItem(Sender: TObject; Item: TListItem;
    8481  Selected: Boolean);
    8582begin
     
    9794procedure TFormTables.UpdateInterface;
    9895begin
    99   ListView1.Enabled := Assigned(Tables);
    100   AAdd.Enabled := Assigned(Tables);
    101   AModify.Enabled := Assigned(Tables) and Assigned(ListView1.Selected);
    102   ARemove.Enabled := Assigned(Tables) and Assigned(ListView1.Selected);
    103   AShowRecords.Enabled := Assigned(Tables) and Assigned(ListView1.Selected);
    104   AShowFields.Enabled := Assigned(Tables) and Assigned(ListView1.Selected);
     96  ListViewTables.Enabled := Assigned(Tables) and Assigned(FDbClient);
     97  AAdd.Enabled := Assigned(Tables) and Assigned(FDbClient);
     98  AModify.Enabled := Assigned(Tables) and Assigned(ListViewTables.Selected) and Assigned(FDbClient);
     99  ARemove.Enabled := Assigned(Tables) and Assigned(ListViewTables.Selected) and Assigned(FDbClient);
     100  AShowRecords.Enabled := Assigned(Tables) and Assigned(ListViewTables.Selected) and Assigned(FDbClient);
     101  AShowFields.Enabled := Assigned(Tables) and Assigned(ListViewTables.Selected) and Assigned(FDbClient);
    105102end;
    106103
     
    112109  NewTable.Name := SNewTable;
    113110  NewTable.DbClient := Tables.DbClient;
    114   FormTable.Load(NewTable);
    115   if FormTable.ShowModal = mrOk then begin
    116     FormTable.Save(NewTable);
    117     Tables.DbClient.Query('INSERT INTO Model ( Name , Caption ) VALUES ( ' +
    118       NewTable.Name + ' , ' + NewTable.Caption + ' )');
    119     ReloadList;
    120   end else NewTable.Free;
     111  with TFormTable.Create(nil) do
     112  try
     113    Load(NewTable);
     114    if ShowModal = mrOk then begin
     115      Save(NewTable);
     116      Tables.DbClient.Query('INSERT INTO Model ( Name , Caption ) VALUES ( ' +
     117        NewTable.Name + ' , ' + NewTable.Caption + ' )');
     118      ReloadList;
     119    end else NewTable.Free;
     120  finally
     121    Free;
     122  end;
    121123end;
    122124
    123125procedure TFormTables.AModifyExecute(Sender: TObject);
    124126begin
    125   if Assigned(ListView1.Selected) then begin
    126     FormTable.Load(TTable(ListView1.Selected.Data));
    127     if FormTable.ShowModal = mrOk then begin
    128       FormTable.Save(TTable(ListView1.Selected.Data));
    129       DbClient.Query('UPDATE Model SET Caption = ' + TTable(ListView1.Selected.Data).Caption + ' WHERE Name = ' + TTable(ListView1.Selected.Data).Name);
    130       ReloadList;
     127  if Assigned(ListViewTables.Selected) then begin
     128    with TFormTable.Create(nil) do
     129    try
     130      Load(TTable(ListViewTables.Selected.Data));
     131      if ShowModal = mrOk then begin
     132        Save(TTable(ListViewTables.Selected.Data));
     133        DbClient.Query('UPDATE Model SET Caption = ' + TTable(ListViewTables.Selected.Data).Caption + ' WHERE Name = ' + TTable(ListViewTables.Selected.Data).Name);
     134        ReloadList;
     135      end;
     136    finally
     137      Free;
    131138    end;
    132139  end;
     
    135142procedure TFormTables.ARemoveExecute(Sender: TObject);
    136143begin
    137   if Assigned(ListView1.Selected) then begin
    138     if MessageDlg(SRemoveTable, Format(SRemoveTableConfirm, [TTable(ListView1.Selected.Data).Caption]),
     144  if Assigned(ListViewTables.Selected) then begin
     145    if MessageDlg(SRemoveTable, Format(SRemoveTableConfirm, [TTable(ListViewTables.Selected.Data).Caption]),
    139146    mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
    140       Tables.DbClient.Query('DELETE FROM Model WHERE Name = ' + TTable(ListView1.Selected.Data).Name);
     147      Tables.DbClient.Query('DELETE FROM Model WHERE Name = ' + TTable(ListViewTables.Selected.Data).Name);
    141148      ReloadList;
    142149    end;
     
    152159  OldField: TField;
    153160  OldTable: TTable;
    154 begin
    155   if Assigned(ListView1.Selected) then begin
    156     OldTable := TTable(ListView1.Selected.Data);
     161  FormFields: TFormFields;
     162begin
     163  if Assigned(ListViewTables.Selected) then begin
     164    OldTable := TTable(ListViewTables.Selected.Data);
     165    FormFields := TFormFields.Create(nil);
    157166    FormFields.TableName := OldTable.Caption;
    158167    FormFields.Fields := TFields.Create;
     
    160169    FormFields.Fields.Assign(OldTable.Fields);
    161170    for I := 0 to FormFields.Fields.Count - 1 do
    162       TField(FormFields.Fields[I]).Table := TField(OldTable.Fields[I]).Table;
     171      FormFields.Fields[I].Table := OldTable.Fields[I].Table;
    163172    if FormFields.ShowModal = mrOk then begin
    164173      // Inefficient way to update table data. Copy original columns to new records and
     
    168177      for I := 0 to NewRecords.Count - 1 do begin
    169178        NewRecords.Items[I] := TRecord.Create;
    170         TRecord(NewRecords.Items[I]).Values.Count := FormFields.Fields.Count;
     179        NewRecords[I].Values.Count := FormFields.Fields.Count;
    171180        for C := 0 to FormFields.Fields.Count - 1 do
    172           TRecord(NewRecords.Items[I]).Values[C] := TField(FormFields.Fields[C]).GetValueClass.Create;
     181          NewRecords[I].Values[C] := FormFields.Fields[C].GetValueClass.Create;
    173182      end;
    174183      for C := 0 to FormFields.Fields.Count - 1 do begin
    175         OldField := OldTable.Fields.SearchByName(TField(FormFields.Fields[C]).Name);
     184        OldField := OldTable.Fields.SearchByName(FormFields.Fields[C].Name);
    176185        if Assigned(OldField) then begin
    177186          FI := OldTable.Fields.IndexOf(OldField);
    178187          for I := 0 to NewRecords.Count - 1 do
    179             TValue(TRecord(NewRecords[I]).Values[C]).Assign(TValue(TRecord(OldTable.Records[I]).Values[FI]));
     188            NewRecords[I].Values[C].Assign(OldTable.Records[I].Values[FI]);
    180189        end;
    181190      end;
     
    186195    end;
    187196    FormFields.Fields.Free;
     197    FormFields.Free;
    188198  end;
    189199end;
     
    191201procedure TFormTables.AShowRecordsExecute(Sender: TObject);
    192202begin
    193   if Assigned(ListView1.Selected) then begin
    194     FormRecords.Table := TTable(ListView1.Selected.Data);
    195     FormRecords.ShowModal;
     203  if Assigned(ListViewTables.Selected) then begin
     204    with TFormRecords.Create(nil) do
     205    try
     206      Table := TTable(ListViewTables.Selected.Data);
     207      ShowModal;
     208    finally
     209      Free;
     210    end;
    196211    ReloadList;
    197212  end;
     
    227242  if Assigned(DbClient) then begin
    228243    DbRows := TDbRows.Create;
    229     DbClient.Query('SELECT * FROM Model', DbRows);
    230     for I := 0 to DbRows.Count - 1 do begin
    231       NewTable := Tables.AddNew(DbRows[I].Items['Name']);
    232       NewTable.Caption := DbRows[I].Items['Caption'];
    233     end;
    234     DbRows.Free;
     244    try
     245      DbClient.Query('SELECT * FROM Model', DbRows);
     246      for I := 0 to DbRows.Count - 1 do begin
     247        NewTable := Tables.AddNew(DbRows[I].Items['Name']);
     248        NewTable.Caption := DbRows[I].Items['Caption'];
     249      end;
     250    finally
     251      DbRows.Free;
     252    end;
    235253  end;
    236254
    237255  for I := 0 to Tables.Count - 1 do
    238     TTable(Tables[I]).LoadRecordsCount;
     256    Tables[I].LoadRecordsCount;
    239257  if Assigned(Tables) then begin
    240     ListView1.Items.Count := Tables.Count;
    241     ListView1.Repaint;
    242   end else ListView1.Items.Count := 0;
     258    ListViewTables.Items.Count := Tables.Count;
     259    ListViewTables.Repaint;
     260  end else ListViewTables.Items.Count := 0;
    243261  UpdateInterface;
    244262end;
  • trunk/Languages/MyData.cs.po

    r27 r28  
    5353
    5454#: tformconnect.caption
    55 msgid "Connection parameters:"
    56 msgstr "Parametry spojení:"
     55msgid "Connection parameters"
     56msgstr "Parametry spojení"
    5757
    5858#: tformconnect.label1.caption
     
    289289
    290290#: tformrecord.caption
    291 #, fuzzy
    292 #| msgid "Record"
    293291msgid "Record"
    294292msgstr "Záznam"
     
    314312msgstr "Záznamy"
    315313
    316 #: tformrecords.listview1.columns[0].caption
    317 msgctxt "tformrecords.listview1.columns[0].caption"
     314#: tformrecords.listviewrecords.columns[0].caption
     315msgctxt "tformrecords.listviewrecords.columns[0].caption"
    318316msgid "Name"
    319317msgstr "Jméno"
    320318
    321 #: tformrecords.listview1.columns[1].caption
    322 msgctxt "tformrecords.listview1.columns[1].caption"
     319#: tformrecords.listviewrecords.columns[1].caption
     320msgctxt "tformrecords.listviewrecords.columns[1].caption"
    323321msgid "Records"
    324322msgstr "Záznamy"
     323
     324#: tformtable.buttoncancel.caption
     325msgctxt "tformtable.buttoncancel.caption"
     326msgid "Cancel"
     327msgstr "Zrušit"
     328
     329#: tformtable.buttonok.caption
     330msgctxt "tformtable.buttonok.caption"
     331msgid "Ok"
     332msgstr "Ok"
     333
     334#: tformtable.caption
     335msgctxt "tformtable.caption"
     336msgid "Table"
     337msgstr "Tabulka"
     338
     339#: tformtable.label1.caption
     340msgid "System name:"
     341msgstr "Jméno systému:"
     342
     343#: tformtable.label2.caption
     344msgid "Caption:"
     345msgstr "Titulek:"
    325346
    326347#: tformtables.aadd.caption
     
    352373msgstr "Tabulky"
    353374
    354 #: tformtables.listview1.columns[0].caption
    355 msgctxt "tformtables.listview1.columns[0].caption"
     375#: tformtables.listviewtables.columns[0].caption
     376msgctxt "tformtables.listviewtables.columns[0].caption"
    356377msgid "Name"
    357378msgstr "Jméno"
    358379
    359 #: tformtables.listview1.columns[1].caption
    360 msgctxt "tformtables.listview1.columns[1].caption"
     380#: tformtables.listviewtables.columns[1].caption
     381msgctxt "tformtables.listviewtables.columns[1].caption"
    361382msgid "Records"
    362383msgstr "Záznamy"
     
    441462msgstr "Špatný formát souboru"
    442463
     464#: uformconnect.sanyfile
     465msgid "Any file"
     466msgstr "Jakýkoliv soubor"
     467
     468#: uformconnect.sxmlfiles
     469msgid "XML files"
     470msgstr "XML soubory"
     471
     472#: uformdatabases.snewdatabase
     473msgid "New database"
     474msgstr "Nová databáze"
     475
     476#: uformdatabases.sremovedatabaseconnection
     477msgid "Remove database connection"
     478msgstr "Odstranění databázového spojení"
     479
     480#: uformdatabases.sremovedatabaseconnectionquery
     481#, object-pascal-format
     482msgid "Do you want to really remove database connection %s?"
     483msgstr "Opravdu chcete odstranit databázové spojení %s?"
     484
    443485#: uformfields.sfieldsnotset
    444486msgid "Fields not set"
     
    454496msgstr "Políčka tabulky - %s"
    455497
     498#: uformrecord.stablerecordedit
     499msgid "Table record edit"
     500msgstr "Úprava záznamu tabulky"
     501
    456502#: uformrecords.sremoverecord
    457503msgid "Remove record"
     
    463509
    464510#: uformrecords.stable
     511msgctxt "uformrecords.stable"
    465512msgid "Table"
    466513msgstr "Tabulka"
     
    488535msgid "String to IP address conversion error"
    489536msgstr "Chyba převodu řetězce na IP adresu"
    490 
  • trunk/Languages/MyData.pot

    r27 r28  
    4242
    4343#: tformconnect.caption
    44 msgid "Connection parameters:"
     44msgid "Connection parameters"
    4545msgstr ""
    4646
     
    301301msgstr ""
    302302
    303 #: tformrecords.listview1.columns[0].caption
    304 msgctxt "tformrecords.listview1.columns[0].caption"
     303#: tformrecords.listviewrecords.columns[0].caption
     304msgctxt "tformrecords.listviewrecords.columns[0].caption"
    305305msgid "Name"
    306306msgstr ""
    307307
    308 #: tformrecords.listview1.columns[1].caption
    309 msgctxt "tformrecords.listview1.columns[1].caption"
     308#: tformrecords.listviewrecords.columns[1].caption
     309msgctxt "tformrecords.listviewrecords.columns[1].caption"
    310310msgid "Records"
     311msgstr ""
     312
     313#: tformtable.buttoncancel.caption
     314msgctxt "tformtable.buttoncancel.caption"
     315msgid "Cancel"
     316msgstr ""
     317
     318#: tformtable.buttonok.caption
     319msgctxt "tformtable.buttonok.caption"
     320msgid "Ok"
     321msgstr ""
     322
     323#: tformtable.caption
     324msgctxt "tformtable.caption"
     325msgid "Table"
     326msgstr ""
     327
     328#: tformtable.label1.caption
     329msgid "System name:"
     330msgstr ""
     331
     332#: tformtable.label2.caption
     333msgid "Caption:"
    311334msgstr ""
    312335
     
    339362msgstr ""
    340363
    341 #: tformtables.listview1.columns[0].caption
    342 msgctxt "tformtables.listview1.columns[0].caption"
     364#: tformtables.listviewtables.columns[0].caption
     365msgctxt "tformtables.listviewtables.columns[0].caption"
    343366msgid "Name"
    344367msgstr ""
    345368
    346 #: tformtables.listview1.columns[1].caption
    347 msgctxt "tformtables.listview1.columns[1].caption"
     369#: tformtables.listviewtables.columns[1].caption
     370msgctxt "tformtables.listviewtables.columns[1].caption"
    348371msgid "Records"
    349372msgstr ""
     
    418441msgstr ""
    419442
     443#: uformconnect.sanyfile
     444msgid "Any file"
     445msgstr ""
     446
     447#: uformconnect.sxmlfiles
     448msgid "XML files"
     449msgstr ""
     450
     451#: uformdatabases.snewdatabase
     452msgid "New database"
     453msgstr ""
     454
     455#: uformdatabases.sremovedatabaseconnection
     456msgid "Remove database connection"
     457msgstr ""
     458
     459#: uformdatabases.sremovedatabaseconnectionquery
     460#, object-pascal-format
     461msgid "Do you want to really remove database connection %s?"
     462msgstr ""
     463
    420464#: uformfields.sfieldsnotset
    421465msgid "Fields not set"
     
    431475msgstr ""
    432476
     477#: uformrecord.stablerecordedit
     478msgid "Table record edit"
     479msgstr ""
     480
    433481#: uformrecords.sremoverecord
    434482msgid "Remove record"
     
    440488
    441489#: uformrecords.stable
     490msgctxt "uformrecords.stable"
    442491msgid "Table"
    443492msgstr ""
  • trunk/MyData.lpr

    r26 r28  
    2727  Application.CreateForm(TCore, Core);
    2828  Application.CreateForm(TFormMain, FormMain);
    29   Application.CreateForm(TFormTables, FormTables);
    30   Application.CreateForm(TFormTable, FormTable);
    31   Application.CreateForm(TFormRecords, FormRecords);
    32   Application.CreateForm(TFormRecord, FormRecord);
    33   Application.CreateForm(TFormFields, FormFields);
    34   Application.CreateForm(TFormField, FormField);
    35   Application.CreateForm(TFormConnect, FormConnect);
    36   Application.CreateForm(TFormDatabases, FormDatabases);
    37   Application.CreateForm(TFormPreferences, FormPreferences);
    3829  Application.Run;
    3930end.
  • trunk/UCore.pas

    r26 r28  
    8787procedure TCore.ADatabaseConnectExecute(Sender: TObject);
    8888begin
    89   if FormDatabases.ShowModal = mrOk then begin
    90     DbClient := nil;
    91     DbClient := FormDatabases.SelectedProfile.GetClient;
     89  with TFormDatabases.Create(nil) do
     90  try
     91    if ShowModal = mrOk then begin
     92      DbClient := nil;
     93      DbClient := SelectedProfile.GetClient;
     94    end;
     95  finally
     96    Free;
    9297  end;
    9398end;
     
    106111procedure TCore.APreferencesExecute(Sender: TObject);
    107112begin
    108   FormPreferences.Load(Preferences);
    109   if FormPreferences.ShowModal = mrOk then begin
    110     FormPreferences.Save(Preferences);
     113  with TFormPreferences.Create(nil) do
     114  try
     115    Load(Preferences);
     116    if ShowModal = mrOk then Save(Preferences);
     117  finally
     118    Free;
    111119  end;
    112120end;
     
    125133  if FDbClient = AValue then Exit;
    126134  if Assigned(FDbClient) then begin
     135    FormMain.FormTables.DbClient := nil;
    127136    DbClient.Save;
    128     FDbClient.Free;
     137    FreeAndNil(FDbClient);
    129138  end;
    130139  FDbClient := AValue;
     
    132141    DbClient.Load;
    133142    Preferences.LastDatabaseName := FDbClient.ConnectProfile.Name;
    134     FormTables.DbClient := DbClient;
     143    FormMain.FormTables.DbClient := DbClient;
    135144  end;
    136145  UpdateInterface;
     
    176185      Translator1.POFilesFolder := '/usr/share/MyData/languages';
    177186    {$ENDIF}
    178     FormConnect.Init;
    179187    Initialized := True;
    180188    LoadConfig;
    181     FormDatabases.ReloadList;
    182189    UpdateInterface;
    183190    if Preferences.RememberDatabase then begin
  • trunk/UDatabase.pas

    r26 r28  
    44
    55uses
    6   Classes, SysUtils, ExtCtrls, StdCtrls, EditBtn, dialogs, USqlDatabase,
    7   URegistry, UGenerics, Generics.Collections;
     6  Classes, SysUtils, ExtCtrls, dialogs, USqlDatabase, URegistry, UGenerics,
     7  Generics.Collections;
    88
    99type
     
    561561  Count := Source.Count;
    562562  for I := OldCount to Count - 1 do
    563     //ShowMessage(TValue(Source.Items[I]).ClassName);
    564563    Items[I] := TValueClass(Source.Items[I].ClassType).Create;
    565564  for I := 0 to Count - 1 do
     
    631630begin
    632631  I := 0;
    633   while (I < Count) and (TField(Items[I]).Name <> Name) do Inc(I);
    634   if I < Count then Result := TField(Items[I])
     632  while (I < Count) and (Items[I].Name <> Name) do Inc(I);
     633  if I < Count then Result := Items[I]
    635634    else Result := nil;
    636635end;
     
    672671    FieldIndex := Parent.Fields.IndexOf(Field);
    673672    if Assigned(Field) then begin
    674       if TValue(Values[FieldIndex]).GetString <> AValues.ValueFromIndex[I] then begin
     673      if Values[FieldIndex].GetString <> AValues.ValueFromIndex[I] then begin
    675674        Result := False;
    676675        Break;
     
    686685  Values.Clear;
    687686  for I := 0 to Parent.Fields.Count - 1 do
    688     Values.Add(TField(Parent.Fields[I]).GetValueClass.Create);
     687    Values.Add(Parent.Fields[I].GetValueClass.Create);
    689688end;
    690689
     
    823822  DbRows := TDbRows.Create;
    824823  try
    825     DbClient.Query('SELECT COUNT(*) AS `Count` FROM ' + Name, DbRows);
     824    DbClient.Query('SELECT COUNT(*) FROM ' + Name, DbRows);
    826825    if DbRows.Count = 1 then begin
    827       RecordsCount := StrToInt(DbRows[0].Items['Count']);
     826      RecordsCount := StrToInt(DbRows[0].Items['COUNT(*)']);
    828827    end else RecordsCount := 0;
    829828  finally
     
    852851  FreeAndNil(Fields);
    853852  FreeAndNil(Records);
    854   inherited Destroy;
     853  inherited;
    855854end;
    856855
  • trunk/UHtmlClasses.pas

    r26 r28  
    241241  I := 1;
    242242  Matched := True;
    243   while (I < Length(Source)) and Matched do begin
     243  while (I <= Length(Source)) and Matched do begin
    244244    Matched := False;
    245     if (Source[I] >= 'A') and (Source[I] <= 'Z') then Matched := True;
    246     if (Source[I] >= 'a') and (Source[I] <= 'z') then Matched := True;
    247     if (Source[I] >= '0') and (Source[I] <= '9') then Matched := True;
    248     for J := 1 to Length(Allowed) do
     245    if (Source[I] >= 'A') and (Source[I] <= 'Z') then Matched := True
     246    else if (Source[I] >= 'a') and (Source[I] <= 'z') then Matched := True
     247    else if (Source[I] >= '0') and (Source[I] <= '9') then Matched := True
     248    else for J := 1 to Length(Allowed) do
    249249      if Source[I] = Allowed[J] then Matched := True;
    250250    if Matched then Inc(I);
    251251  end;
    252252  if (Delimiter = Copy(Source, I, Length(Delimiter))) or (I = Length(Source)) then begin
    253     Output := Copy(Source, 1, I-1);
     253    Output := Copy(Source, 1, I - 1);
    254254    Delete(Source, 1, Length(Output) + Length(Delimiter));
    255255    Result := True;
Note: See TracChangeset for help on using the changeset viewer.