Changeset 4 for trunk/Forms/UFormTables.pas
- Timestamp:
- Jan 18, 2015, 11:29:26 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.