Changeset 4 for trunk/Forms


Ignore:
Timestamp:
Jan 18, 2015, 11:29:26 PM (9 years ago)
Author:
chronos
Message:
  • Moved: Field and value data type declaration moved to separate unit.
  • Modified: Fields edit form is now modal and made need changes need to be accepted.
  • Added: 32x32 icons to actions.
  • Fixed: If fileds count or type changed then table values are updated.
Location:
trunk/Forms
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormField.pas

    r3 r4  
    4949
    5050implementation
     51
     52uses
     53  UDataTypes;
    5154
    5255{$R *.lfm}
  • trunk/Forms/UFormFields.lfm

    r2 r4  
    1111  object ToolBar1: TToolBar
    1212    Left = 0
    13     Height = 26
    14     Top = 446
     13    Height = 36
     14    Top = 436
    1515    Width = 940
    1616    Align = alBottom
     17    ButtonHeight = 32
     18    ButtonWidth = 32
    1719    Caption = 'ToolBar1'
    1820    Images = Core.ImageList1
    19     ShowCaptions = True
    2021    TabOrder = 0
    2122    object ToolButton1: TToolButton
     
    2526    end
    2627    object ToolButton2: TToolButton
    27       Left = 46
     28      Left = 37
    2829      Top = 2
    2930      Action = AModify
    3031    end
    3132    object ToolButton3: TToolButton
    32       Left = 118
     33      Left = 73
    3334      Top = 2
    3435      Action = ARemove
     36    end
     37    object ToolButton4: TToolButton
     38      Left = 109
     39      Top = 2
     40      Action = AOk
     41    end
     42    object ToolButton5: TToolButton
     43      Left = 145
     44      Top = 2
     45      Action = ACancel
    3546    end
    3647  end
    3748  object ListView1: TListView
    3849    Left = 4
    39     Height = 438
     50    Height = 428
    4051    Top = 4
    4152    Width = 932
     
    7990    object AAdd: TAction
    8091      Caption = 'Add'
     92      ImageIndex = 5
    8193      OnExecute = AAddExecute
    8294    end
    8395    object AModify: TAction
    8496      Caption = 'Modify'
     97      ImageIndex = 3
    8598      OnExecute = AModifyExecute
    8699    end
    87100    object ARemove: TAction
    88101      Caption = 'Remove'
     102      ImageIndex = 4
    89103      OnExecute = ARemoveExecute
     104    end
     105    object AOk: TAction
     106      Caption = 'Ok'
     107      ImageIndex = 0
     108      OnExecute = AOkExecute
     109    end
     110    object ACancel: TAction
     111      Caption = 'Cancel'
     112      ImageIndex = 1
     113      OnExecute = ACancelExecute
    90114    end
    91115  end
  • trunk/Forms/UFormFields.pas

    r3 r4  
    1515  TFormFields = class(TForm)
    1616    AAdd: TAction;
     17    AOk: TAction;
     18    ACancel: TAction;
    1719    ActionList1: TActionList;
    1820    AModify: TAction;
     
    2729    ToolButton2: TToolButton;
    2830    ToolButton3: TToolButton;
     31    ToolButton4: TToolButton;
     32    ToolButton5: TToolButton;
    2933    procedure AAddExecute(Sender: TObject);
     34    procedure ACancelExecute(Sender: TObject);
    3035    procedure AModifyExecute(Sender: TObject);
     36    procedure AOkExecute(Sender: TObject);
    3137    procedure ARemoveExecute(Sender: TObject);
    3238    procedure FormShow(Sender: TObject);
     
    3743    { private declarations }
    3844  public
    39     Table: TTable;
     45    Fields: TFields;
     46    TableName: string;
    4047    procedure UpdateInterface;
    4148    procedure ReloadList;
     
    4855
    4956uses
    50   UFormField;
     57  UFormField, UDataTypes;
    5158
    5259{$R *.lfm}
     
    5663procedure TFormFields.FormShow(Sender: TObject);
    5764begin
     65  Caption := 'Table fields - ' + TableName;
    5866  UpdateInterface;
    5967  ReloadList;
     
    6977  if FormField.ShowModal = mrOk then begin
    7078    FormField.Save(NewField);
    71     Table.Fields.Add(NewField);
     79    Fields.Add(NewField);
    7280    ReloadList;
    7381  end else NewField.Free;
     82end;
     83
     84procedure TFormFields.ACancelExecute(Sender: TObject);
     85begin
     86  Close;
    7487end;
    7588
     
    8598end;
    8699
     100procedure TFormFields.AOkExecute(Sender: TObject);
     101begin
     102  ModalResult := mrOk;
     103end;
     104
    87105procedure TFormFields.ARemoveExecute(Sender: TObject);
    88106begin
    89107  if Assigned(ListView1.Selected) then begin
    90     Table.Fields.Remove(ListView1.Selected.Data);
     108    Fields.Remove(ListView1.Selected.Data);
    91109    ReloadList;
    92110    UpdateInterface;
     
    96114procedure TFormFields.ListView1Data(Sender: TObject; Item: TListItem);
    97115begin
    98   if (Item.Index >= 0) and (Item.Index < Table.Fields.Count) then
    99   with TField(Table.Fields[Item.Index]) do begin
     116  if (Item.Index >= 0) and (Item.Index < Fields.Count) then
     117  with TField(Fields[Item.Index]) do begin
    100118    Item.Caption := Name;
    101119    Item.SubItems.Add(FieldTypeString[FieldType]);
     
    103121    Item.SubItems.Add(TextBefore);
    104122    Item.SubItems.Add(TextAfter);
    105     Item.Data := Table.Fields[Item.Index];
     123    Item.Data := Fields[Item.Index];
    106124  end;
    107125end;
     
    121139procedure TFormFields.ReloadList;
    122140begin
    123   ListView1.Items.Count := Table.Fields.Count;
     141  ListView1.Items.Count := Fields.Count;
    124142  ListView1.Repaint;
    125143end;
  • trunk/Forms/UFormRecord.lfm

    r3 r4  
    4141  end
    4242  object ActionList1: TActionList
     43    Images = Core.ImageList1
    4344    left = 423
    4445    top = 379
  • trunk/Forms/UFormRecord.pas

    r3 r4  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9   ComCtrls, ActnList, StdCtrls, EditBtn, UDatabase, Contnrs;
     9  ComCtrls, ActnList, StdCtrls, EditBtn, UDatabase, Contnrs, Spin;
    1010
    1111type
     
    4242implementation
    4343
     44uses
     45  UDataTypes;
     46
    4447{$R *.lfm}
    4548
     
    4851procedure TFormRecord.FormShow(Sender: TObject);
    4952begin
     53  Caption := 'Table record edit - ' + Table.Caption;
    5054  ReloadControls;
    5155end;
     
    5458begin
    5559  ModalResult := mrCancel;
    56   Close;
    5760end;
    5861
     
    6063begin
    6164  ModalResult := mrOk;
    62   Close;
    6365end;
    6466
     
    109111        Controls.Add(NewControl);
    110112      end;
     113      ftInteger: begin
     114        NewControl := TSpinEdit.Create(Panel1);
     115        NewControl.Parent := Panel1;
     116        NewControl.Left := CellRect.Left;
     117        NewControl.Top := CellRect.Top + NewLabel.Height + 6;
     118        NewControl.Width := CellRect.Right - CellRect.Left;
     119        NewControl.Visible := True;
     120        TSpinEdit(NewControl).Value := TValueInteger(Row.Values[I]).Value;
     121        Controls.Add(NewControl);
     122      end;
    111123      ftDateTime: begin
    112124        NewControl := TDateEdit.Create(Panel1);
     
    117129        NewControl.Visible := True;
    118130        TDateEdit(NewControl).Date := TValueDateTime(Row.Values[I]).Value;
     131        Controls.Add(NewControl);
     132      end;
     133      ftBoolean: begin
     134        NewControl := TCheckBox.Create(Panel1);
     135        NewControl.Parent := Panel1;
     136        NewControl.Left := CellRect.Left;
     137        NewControl.Top := CellRect.Top + NewLabel.Height + 6;
     138        NewControl.Width := CellRect.Right - CellRect.Left;
     139        NewControl.Visible := True;
     140        TCheckBox(NewControl).Checked := TValueBoolean(Row.Values[I]).Value;
    119141        Controls.Add(NewControl);
    120142      end;
     
    130152    case TField(Table.Fields[I]).FieldType of
    131153      ftString: TValueString(Row.Values[I]).Value := TEdit(Controls[I]).Text;
     154      ftInteger: TValueInteger(Row.Values[I]).Value := TSpinEdit(Controls[I]).Value;
    132155      ftDateTime: TValueDateTime(Row.Values[I]).Value := TDateEdit(Controls[I]).Date;
     156      ftBoolean: TValueBoolean(Row.Values[I]).Value := TCheckBox(Controls[I]).Checked;
    133157    end;
    134158  end;
  • trunk/Forms/UFormRecords.lfm

    r3 r4  
    1111  object ListView1: TListView
    1212    Left = 4
    13     Height = 399
     13    Height = 389
    1414    Top = 4
    1515    Width = 851
     
    3737  object ToolBar1: TToolBar
    3838    Left = 0
    39     Height = 26
    40     Top = 407
     39    Height = 36
     40    Top = 397
    4141    Width = 859
    4242    Align = alBottom
     43    ButtonHeight = 32
     44    ButtonWidth = 32
    4345    Caption = 'ToolBar1'
    4446    Images = Core.ImageList1
    45     ShowCaptions = True
    4647    TabOrder = 1
    4748    object ToolButton1: TToolButton
     
    5152    end
    5253    object ToolButton2: TToolButton
    53       Left = 46
     54      Left = 37
    5455      Top = 2
    5556      Action = AModify
    5657    end
    5758    object ToolButton3: TToolButton
    58       Left = 118
     59      Left = 73
    5960      Top = 2
    6061      Action = ARemove
     
    6768    object AAdd: TAction
    6869      Caption = 'Add'
     70      ImageIndex = 5
    6971      OnExecute = AAddExecute
    7072    end
    7173    object AModify: TAction
    7274      Caption = 'Modify'
     75      ImageIndex = 3
    7376      OnExecute = AModifyExecute
    7477    end
    7578    object ARemove: TAction
    7679      Caption = 'Remove'
     80      ImageIndex = 4
    7781      OnExecute = ARemoveExecute
    7882    end
  • trunk/Forms/UFormRecords.pas

    r3 r4  
    5656procedure TFormRecords.FormShow(Sender: TObject);
    5757begin
    58   Caption := 'Table - ' + Table.Name;
     58  Caption := 'Table - ' + Table.Caption;
    5959  ReloadList;
    6060end;
  • trunk/Forms/UFormTable.lfm

    r2 r4  
    1919    Height = 25
    2020    Top = 21
    21     Width = 62
    22     Caption = 'Name:'
     21    Width = 131
     22    Caption = 'System name:'
    2323    ParentColor = False
    2424  end
     
    2828    Top = 302
    2929    Width = 75
     30    Anchors = [akRight, akBottom]
    3031    Caption = 'Ok'
    3132    ModalResult = 1
    3233    TabOrder = 1
    3334  end
     35  object EditCaption: TEdit
     36    Left = 167
     37    Height = 35
     38    Top = 56
     39    Width = 156
     40    TabOrder = 2
     41  end
     42  object Label2: TLabel
     43    Left = 16
     44    Height = 25
     45    Top = 66
     46    Width = 78
     47    Caption = 'Caption:'
     48    ParentColor = False
     49  end
     50  object ButtonCancel: TButton
     51    Left = 472
     52    Height = 25
     53    Top = 302
     54    Width = 75
     55    Anchors = [akRight, akBottom]
     56    Caption = 'Cancel'
     57    ModalResult = 2
     58    TabOrder = 3
     59  end
    3460end
  • trunk/Forms/UFormTable.pas

    r2 r4  
    1515  TFormTable = class(TForm)
    1616    ButtonOk: TButton;
     17    ButtonCancel: TButton;
    1718    EditName: TEdit;
     19    EditCaption: TEdit;
    1820    Label1: TLabel;
     21    Label2: TLabel;
    1922  private
    2023    { private declarations }
     
    3639begin
    3740  EditName.Text := Table.Name;
     41  EditCaption.Text := Table.Caption;
    3842end;
    3943
     
    4145begin
    4246  Table.Name := EditName.Text;
     47  Table.Caption := EditCaption.Text;
    4348end;
    4449
  • trunk/Forms/UFormTables.lfm

    r3 r4  
    1313  object ListView1: TListView
    1414    Left = 4
    15     Height = 626
     15    Height = 616
    1616    Top = 4
    1717    Width = 970
     
    3939  object ToolBar1: TToolBar
    4040    Left = 0
    41     Height = 26
    42     Top = 634
     41    Height = 36
     42    Top = 624
    4343    Width = 978
    4444    Align = alBottom
     45    ButtonHeight = 32
     46    ButtonWidth = 32
    4547    Caption = 'ToolBar1'
    4648    Images = Core.ImageList1
    47     ShowCaptions = True
    4849    TabOrder = 1
    4950    object ToolButton1: TToolButton
     
    5354    end
    5455    object ToolButton2: TToolButton
    55       Left = 46
     56      Left = 37
    5657      Top = 2
    5758      Action = AModify
    5859    end
    5960    object ToolButton3: TToolButton
    60       Left = 118
     61      Left = 73
    6162      Top = 2
    6263      Action = ARemove
    6364    end
    6465    object ToolButton4: TToolButton
    65       Left = 201
     66      Left = 109
    6667      Top = 2
    6768      Action = AShowRecords
    6869    end
    6970    object ToolButton5: TToolButton
    70       Left = 283
     71      Left = 145
    7172      Top = 2
    7273      Action = AShowFields
     
    7980    object AAdd: TAction
    8081      Caption = 'Add'
     82      ImageIndex = 5
    8183      OnExecute = AAddExecute
    8284    end
    8385    object AModify: TAction
    8486      Caption = 'Modify'
     87      ImageIndex = 3
    8588      OnExecute = AModifyExecute
    8689    end
    8790    object ARemove: TAction
    8891      Caption = 'Remove'
     92      ImageIndex = 4
    8993      OnExecute = ARemoveExecute
    9094    end
    9195    object AShowRecords: TAction
    9296      Caption = 'Records'
     97      ImageIndex = 7
    9398      OnExecute = AShowRecordsExecute
    9499    end
    95100    object AShowFields: TAction
    96101      Caption = 'Design'
     102      ImageIndex = 6
    97103      OnExecute = AShowFieldsExecute
    98104    end
  • trunk/Forms/UFormTables.pas

    r3 r4  
    6868  if (Item.Index >= 0) and (Item.Index < Database.Tables.Count) then
    6969  with TTable(Database.Tables[Item.Index]) do begin
    70     Item.Caption := Name;
     70    Item.Caption := Caption;
    7171    Item.SubItems.Add(IntToStr(Records.Count));
    7272    Item.Data := Database.Tables[Item.Index];
     
    116116begin
    117117  if Assigned(ListView1.Selected) then begin
    118     Database.Tables.Remove(ListView1.Selected.Data);
    119     ReloadList;
     118    if MessageDlg('Remove table', 'Do you want to really remove table ' +
     119    TTable(ListView1.Selected.Data).Name, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
     120      Database.Tables.Remove(ListView1.Selected.Data);
     121      ReloadList;
     122    end;
    120123  end;
    121124end;
    122125
    123126procedure TFormMain.AShowFieldsExecute(Sender: TObject);
    124 begin
    125   if Assigned(ListView1.Selected) then begin
    126     FormFields.Table := TTable(ListView1.Selected.Data);
    127     FormFields.ShowModal;
    128     ReloadList;
     127var
     128  NewRecords: TRecords;
     129  I: Integer;
     130  FI: Integer;
     131  C: Integer;
     132  OldField: TField;
     133  OldTable: TTable;
     134begin
     135  if Assigned(ListView1.Selected) then begin
     136    OldTable := TTable(ListView1.Selected.Data);
     137    FormFields.TableName := OldTable.Caption;
     138    FormFields.Fields := TFields.Create;
     139    FormFields.Fields.Assign(OldTable.Fields);
     140    if FormFields.ShowModal = mrOk then begin
     141      // Inefficient way to update table data. Copy original columns to new records and
     142      // then replace original table records
     143      NewRecords := TRecords.Create;
     144      NewRecords.Count := OldTable.Records.Count;
     145      for I := 0 to NewRecords.Count - 1 do begin
     146        NewRecords.Items[I] := TRecord.Create;
     147        TRecord(NewRecords.Items[I]).Values.Count := FormFields.Fields.Count;
     148        for C := 0 to FormFields.Fields.Count - 1 do
     149          TRecord(NewRecords.Items[I]).Values[C] := TField(FormFields.Fields[C]).GetValueClass.Create;
     150      end;
     151      for C := 0 to FormFields.Fields.Count - 1 do begin
     152        OldField := OldTable.Fields.FindByName(TField(FormFields.Fields[C]).Name);
     153        if Assigned(OldField) then begin
     154          FI := OldTable.Fields.IndexOf(OldField);
     155          for I := 0 to NewRecords.Count - 1 do
     156            TValue(TRecord(NewRecords[I]).Values[C]).Assign(TValue(TRecord(OldTable.Records[I]).Values[FI]));
     157        end;
     158      end;
     159      OldTable.Fields.Assign(FormFields.Fields);
     160      OldTable.Records.Assign(NewRecords);
     161      NewRecords.Free;
     162      ReloadList;
     163    end;
     164    FormFields.Fields.Free;
    129165  end;
    130166end;
Note: See TracChangeset for help on using the changeset viewer.