Changeset 4 for trunk/Forms
- Timestamp:
- Jan 18, 2015, 11:29:26 PM (10 years ago)
- Location:
- trunk/Forms
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormField.pas
r3 r4 49 49 50 50 implementation 51 52 uses 53 UDataTypes; 51 54 52 55 {$R *.lfm} -
trunk/Forms/UFormFields.lfm
r2 r4 11 11 object ToolBar1: TToolBar 12 12 Left = 0 13 Height = 2614 Top = 4 4613 Height = 36 14 Top = 436 15 15 Width = 940 16 16 Align = alBottom 17 ButtonHeight = 32 18 ButtonWidth = 32 17 19 Caption = 'ToolBar1' 18 20 Images = Core.ImageList1 19 ShowCaptions = True20 21 TabOrder = 0 21 22 object ToolButton1: TToolButton … … 25 26 end 26 27 object ToolButton2: TToolButton 27 Left = 4628 Left = 37 28 29 Top = 2 29 30 Action = AModify 30 31 end 31 32 object ToolButton3: TToolButton 32 Left = 11833 Left = 73 33 34 Top = 2 34 35 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 35 46 end 36 47 end 37 48 object ListView1: TListView 38 49 Left = 4 39 Height = 4 3850 Height = 428 40 51 Top = 4 41 52 Width = 932 … … 79 90 object AAdd: TAction 80 91 Caption = 'Add' 92 ImageIndex = 5 81 93 OnExecute = AAddExecute 82 94 end 83 95 object AModify: TAction 84 96 Caption = 'Modify' 97 ImageIndex = 3 85 98 OnExecute = AModifyExecute 86 99 end 87 100 object ARemove: TAction 88 101 Caption = 'Remove' 102 ImageIndex = 4 89 103 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 90 114 end 91 115 end -
trunk/Forms/UFormFields.pas
r3 r4 15 15 TFormFields = class(TForm) 16 16 AAdd: TAction; 17 AOk: TAction; 18 ACancel: TAction; 17 19 ActionList1: TActionList; 18 20 AModify: TAction; … … 27 29 ToolButton2: TToolButton; 28 30 ToolButton3: TToolButton; 31 ToolButton4: TToolButton; 32 ToolButton5: TToolButton; 29 33 procedure AAddExecute(Sender: TObject); 34 procedure ACancelExecute(Sender: TObject); 30 35 procedure AModifyExecute(Sender: TObject); 36 procedure AOkExecute(Sender: TObject); 31 37 procedure ARemoveExecute(Sender: TObject); 32 38 procedure FormShow(Sender: TObject); … … 37 43 { private declarations } 38 44 public 39 Table: TTable; 45 Fields: TFields; 46 TableName: string; 40 47 procedure UpdateInterface; 41 48 procedure ReloadList; … … 48 55 49 56 uses 50 UFormField ;57 UFormField, UDataTypes; 51 58 52 59 {$R *.lfm} … … 56 63 procedure TFormFields.FormShow(Sender: TObject); 57 64 begin 65 Caption := 'Table fields - ' + TableName; 58 66 UpdateInterface; 59 67 ReloadList; … … 69 77 if FormField.ShowModal = mrOk then begin 70 78 FormField.Save(NewField); 71 Table.Fields.Add(NewField);79 Fields.Add(NewField); 72 80 ReloadList; 73 81 end else NewField.Free; 82 end; 83 84 procedure TFormFields.ACancelExecute(Sender: TObject); 85 begin 86 Close; 74 87 end; 75 88 … … 85 98 end; 86 99 100 procedure TFormFields.AOkExecute(Sender: TObject); 101 begin 102 ModalResult := mrOk; 103 end; 104 87 105 procedure TFormFields.ARemoveExecute(Sender: TObject); 88 106 begin 89 107 if Assigned(ListView1.Selected) then begin 90 Table.Fields.Remove(ListView1.Selected.Data);108 Fields.Remove(ListView1.Selected.Data); 91 109 ReloadList; 92 110 UpdateInterface; … … 96 114 procedure TFormFields.ListView1Data(Sender: TObject; Item: TListItem); 97 115 begin 98 if (Item.Index >= 0) and (Item.Index < Table.Fields.Count) then99 with TField( Table.Fields[Item.Index]) do begin116 if (Item.Index >= 0) and (Item.Index < Fields.Count) then 117 with TField(Fields[Item.Index]) do begin 100 118 Item.Caption := Name; 101 119 Item.SubItems.Add(FieldTypeString[FieldType]); … … 103 121 Item.SubItems.Add(TextBefore); 104 122 Item.SubItems.Add(TextAfter); 105 Item.Data := Table.Fields[Item.Index];123 Item.Data := Fields[Item.Index]; 106 124 end; 107 125 end; … … 121 139 procedure TFormFields.ReloadList; 122 140 begin 123 ListView1.Items.Count := Table.Fields.Count;141 ListView1.Items.Count := Fields.Count; 124 142 ListView1.Repaint; 125 143 end; -
trunk/Forms/UFormRecord.lfm
r3 r4 41 41 end 42 42 object ActionList1: TActionList 43 Images = Core.ImageList1 43 44 left = 423 44 45 top = 379 -
trunk/Forms/UFormRecord.pas
r3 r4 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, 9 ComCtrls, ActnList, StdCtrls, EditBtn, UDatabase, Contnrs ;9 ComCtrls, ActnList, StdCtrls, EditBtn, UDatabase, Contnrs, Spin; 10 10 11 11 type … … 42 42 implementation 43 43 44 uses 45 UDataTypes; 46 44 47 {$R *.lfm} 45 48 … … 48 51 procedure TFormRecord.FormShow(Sender: TObject); 49 52 begin 53 Caption := 'Table record edit - ' + Table.Caption; 50 54 ReloadControls; 51 55 end; … … 54 58 begin 55 59 ModalResult := mrCancel; 56 Close;57 60 end; 58 61 … … 60 63 begin 61 64 ModalResult := mrOk; 62 Close;63 65 end; 64 66 … … 109 111 Controls.Add(NewControl); 110 112 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; 111 123 ftDateTime: begin 112 124 NewControl := TDateEdit.Create(Panel1); … … 117 129 NewControl.Visible := True; 118 130 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; 119 141 Controls.Add(NewControl); 120 142 end; … … 130 152 case TField(Table.Fields[I]).FieldType of 131 153 ftString: TValueString(Row.Values[I]).Value := TEdit(Controls[I]).Text; 154 ftInteger: TValueInteger(Row.Values[I]).Value := TSpinEdit(Controls[I]).Value; 132 155 ftDateTime: TValueDateTime(Row.Values[I]).Value := TDateEdit(Controls[I]).Date; 156 ftBoolean: TValueBoolean(Row.Values[I]).Value := TCheckBox(Controls[I]).Checked; 133 157 end; 134 158 end; -
trunk/Forms/UFormRecords.lfm
r3 r4 11 11 object ListView1: TListView 12 12 Left = 4 13 Height = 3 9913 Height = 389 14 14 Top = 4 15 15 Width = 851 … … 37 37 object ToolBar1: TToolBar 38 38 Left = 0 39 Height = 2640 Top = 40739 Height = 36 40 Top = 397 41 41 Width = 859 42 42 Align = alBottom 43 ButtonHeight = 32 44 ButtonWidth = 32 43 45 Caption = 'ToolBar1' 44 46 Images = Core.ImageList1 45 ShowCaptions = True46 47 TabOrder = 1 47 48 object ToolButton1: TToolButton … … 51 52 end 52 53 object ToolButton2: TToolButton 53 Left = 4654 Left = 37 54 55 Top = 2 55 56 Action = AModify 56 57 end 57 58 object ToolButton3: TToolButton 58 Left = 11859 Left = 73 59 60 Top = 2 60 61 Action = ARemove … … 67 68 object AAdd: TAction 68 69 Caption = 'Add' 70 ImageIndex = 5 69 71 OnExecute = AAddExecute 70 72 end 71 73 object AModify: TAction 72 74 Caption = 'Modify' 75 ImageIndex = 3 73 76 OnExecute = AModifyExecute 74 77 end 75 78 object ARemove: TAction 76 79 Caption = 'Remove' 80 ImageIndex = 4 77 81 OnExecute = ARemoveExecute 78 82 end -
trunk/Forms/UFormRecords.pas
r3 r4 56 56 procedure TFormRecords.FormShow(Sender: TObject); 57 57 begin 58 Caption := 'Table - ' + Table. Name;58 Caption := 'Table - ' + Table.Caption; 59 59 ReloadList; 60 60 end; -
trunk/Forms/UFormTable.lfm
r2 r4 19 19 Height = 25 20 20 Top = 21 21 Width = 6222 Caption = ' Name:'21 Width = 131 22 Caption = 'System name:' 23 23 ParentColor = False 24 24 end … … 28 28 Top = 302 29 29 Width = 75 30 Anchors = [akRight, akBottom] 30 31 Caption = 'Ok' 31 32 ModalResult = 1 32 33 TabOrder = 1 33 34 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 34 60 end -
trunk/Forms/UFormTable.pas
r2 r4 15 15 TFormTable = class(TForm) 16 16 ButtonOk: TButton; 17 ButtonCancel: TButton; 17 18 EditName: TEdit; 19 EditCaption: TEdit; 18 20 Label1: TLabel; 21 Label2: TLabel; 19 22 private 20 23 { private declarations } … … 36 39 begin 37 40 EditName.Text := Table.Name; 41 EditCaption.Text := Table.Caption; 38 42 end; 39 43 … … 41 45 begin 42 46 Table.Name := EditName.Text; 47 Table.Caption := EditCaption.Text; 43 48 end; 44 49 -
trunk/Forms/UFormTables.lfm
r3 r4 13 13 object ListView1: TListView 14 14 Left = 4 15 Height = 6 2615 Height = 616 16 16 Top = 4 17 17 Width = 970 … … 39 39 object ToolBar1: TToolBar 40 40 Left = 0 41 Height = 2642 Top = 6 3441 Height = 36 42 Top = 624 43 43 Width = 978 44 44 Align = alBottom 45 ButtonHeight = 32 46 ButtonWidth = 32 45 47 Caption = 'ToolBar1' 46 48 Images = Core.ImageList1 47 ShowCaptions = True48 49 TabOrder = 1 49 50 object ToolButton1: TToolButton … … 53 54 end 54 55 object ToolButton2: TToolButton 55 Left = 4656 Left = 37 56 57 Top = 2 57 58 Action = AModify 58 59 end 59 60 object ToolButton3: TToolButton 60 Left = 11861 Left = 73 61 62 Top = 2 62 63 Action = ARemove 63 64 end 64 65 object ToolButton4: TToolButton 65 Left = 20166 Left = 109 66 67 Top = 2 67 68 Action = AShowRecords 68 69 end 69 70 object ToolButton5: TToolButton 70 Left = 28371 Left = 145 71 72 Top = 2 72 73 Action = AShowFields … … 79 80 object AAdd: TAction 80 81 Caption = 'Add' 82 ImageIndex = 5 81 83 OnExecute = AAddExecute 82 84 end 83 85 object AModify: TAction 84 86 Caption = 'Modify' 87 ImageIndex = 3 85 88 OnExecute = AModifyExecute 86 89 end 87 90 object ARemove: TAction 88 91 Caption = 'Remove' 92 ImageIndex = 4 89 93 OnExecute = ARemoveExecute 90 94 end 91 95 object AShowRecords: TAction 92 96 Caption = 'Records' 97 ImageIndex = 7 93 98 OnExecute = AShowRecordsExecute 94 99 end 95 100 object AShowFields: TAction 96 101 Caption = 'Design' 102 ImageIndex = 6 97 103 OnExecute = AShowFieldsExecute 98 104 end -
trunk/Forms/UFormTables.pas
r3 r4 68 68 if (Item.Index >= 0) and (Item.Index < Database.Tables.Count) then 69 69 with TTable(Database.Tables[Item.Index]) do begin 70 Item.Caption := Name;70 Item.Caption := Caption; 71 71 Item.SubItems.Add(IntToStr(Records.Count)); 72 72 Item.Data := Database.Tables[Item.Index]; … … 116 116 begin 117 117 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; 120 123 end; 121 124 end; 122 125 123 126 procedure 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; 127 var 128 NewRecords: TRecords; 129 I: Integer; 130 FI: Integer; 131 C: Integer; 132 OldField: TField; 133 OldTable: TTable; 134 begin 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; 129 165 end; 130 166 end;
Note:
See TracChangeset
for help on using the changeset viewer.