Changeset 3 for trunk/Forms/UFormRecords.pas
- Timestamp:
- Jan 18, 2015, 5:25:37 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 3 3 MyData.lps 4 4 data.xml 5 Config.xml
-
- Property svn:ignore
-
trunk/Forms/UFormRecords.pas
r2 r3 31 31 procedure ARemoveExecute(Sender: TObject); 32 32 procedure FormShow(Sender: TObject); 33 procedure ListView1Data(Sender: TObject; Item: TListItem); 33 34 procedure ListView1SelectItem(Sender: TObject; Item: TListItem; 34 35 Selected: Boolean); … … 46 47 implementation 47 48 49 uses 50 UFormRecord; 51 48 52 {$R *.lfm} 49 53 … … 53 57 begin 54 58 Caption := 'Table - ' + Table.Name; 55 UpdateInterface; 59 ReloadList; 60 end; 61 62 procedure TFormRecords.ListView1Data(Sender: TObject; Item: TListItem); 63 var 64 I: Integer; 65 begin 66 if (Item.Index >= 0) and (Item.Index < Table.Records.Count) then 67 with TRecord(Table.Records[Item.Index]) do begin 68 for I := 0 to Table.Fields.Count - 1 do begin 69 if I = 0 then Item.Caption := TValue(Values[0]).GetString 70 else Item.SubItems.Add(TValue(Values[I]).GetString); 71 end; 72 Item.Data := Table.Records[Item.Index]; 73 end 56 74 end; 57 75 … … 64 82 procedure TFormRecords.AModifyExecute(Sender: TObject); 65 83 begin 66 84 if Assigned(ListView1.Selected) then begin 85 FormRecord.Table := Table; 86 FormRecord.Load(TRecord(ListView1.Selected.Data)); 87 if FormRecord.ShowModal = mrOk then begin 88 FormRecord.Save(TRecord(ListView1.Selected.Data)); 89 ReloadList; 90 end; 91 end; 67 92 end; 68 93 69 94 procedure TFormRecords.ARemoveExecute(Sender: TObject); 70 95 begin 71 96 if Assigned(ListView1.Selected) then begin 97 Table.Records.Remove(ListView1.Selected.Data); 98 ReloadList; 99 end; 72 100 end; 73 101 74 102 procedure TFormRecords.AAddExecute(Sender: TObject); 103 var 104 NewRecord: TRecord; 105 ValueClass: TValueClass; 106 I: Integer; 107 NewValue: TValue; 75 108 begin 109 NewRecord := TRecord.Create; 110 NewRecord.Parent := Table; 111 NewRecord.Values.Count := Table.Fields.Count; 112 for I := 0 to Table.Fields.Count - 1 do begin 113 ValueClass := TField(Table.Fields[I]).GetValueClass; 114 NewValue := ValueClass.Create; 115 NewRecord.Values[I] := NewValue; 116 end; 76 117 118 FormRecord.Table := Table; 119 FormRecord.Load(NewRecord); 120 if FormRecord.ShowModal = mrOk then begin 121 FormRecord.Save(NewRecord); 122 Table.Records.Add(NewRecord); 123 ReloadList; 124 end else NewRecord.Free; 77 125 end; 78 126 … … 84 132 85 133 procedure TFormRecords.ReloadList; 134 var 135 I: Integer; 136 NewColumn: TListColumn; 86 137 begin 138 ListView1.Columns.Clear; 139 for I := 0 to Table.Fields.Count - 1 do begin 140 NewColumn := ListView1.Columns.Add; 141 NewColumn.Caption := TField(Table.Fields[I]).TextBefore; 142 NewColumn.Width := 200; 143 end; 144 87 145 ListView1.Items.Count := Table.Records.Count; 88 146 ListView1.Repaint;
Note:
See TracChangeset
for help on using the changeset viewer.