Changeset 3 for trunk/Forms/UFormRecord.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/UFormRecord.pas
r2 r3 6 6 7 7 uses 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, UDatabase; 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, 9 ComCtrls, ActnList, StdCtrls, EditBtn, UDatabase, Contnrs; 9 10 10 11 type 12 13 { TFormRecord } 14 11 15 TFormRecord = class(TForm) 16 ASave: TAction; 17 ACancel: TAction; 18 ActionList1: TActionList; 19 ButtonOk: TButton; 20 ButtonCancel: TButton; 21 Panel1: TPanel; 22 procedure ACancelExecute(Sender: TObject); 23 procedure ASaveExecute(Sender: TObject); 24 procedure FormCreate(Sender: TObject); 25 procedure FormDestroy(Sender: TObject); 26 procedure FormShow(Sender: TObject); 12 27 private 13 28 { private declarations } … … 15 30 Table: TTable; 16 31 Row: TRecord; 32 Controls: TObjectList; // TListObject<TControl> 33 Labels: TObjectList; // TListObject<TControl> 34 procedure ReloadControls; 35 procedure Load(DataRecord: TRecord); 36 procedure Save(DataRecord: TRecord); 17 37 end; 18 38 … … 24 44 {$R *.lfm} 25 45 46 { TFormRecord } 47 48 procedure TFormRecord.FormShow(Sender: TObject); 49 begin 50 ReloadControls; 51 end; 52 53 procedure TFormRecord.ACancelExecute(Sender: TObject); 54 begin 55 ModalResult := mrCancel; 56 Close; 57 end; 58 59 procedure TFormRecord.ASaveExecute(Sender: TObject); 60 begin 61 ModalResult := mrOk; 62 Close; 63 end; 64 65 procedure TFormRecord.FormCreate(Sender: TObject); 66 begin 67 Controls := TObjectList.Create; 68 Labels := TObjectList.Create; 69 end; 70 71 procedure TFormRecord.FormDestroy(Sender: TObject); 72 begin 73 Labels.Free; 74 Controls.Free; 75 end; 76 77 procedure TFormRecord.ReloadControls; 78 begin 79 end; 80 81 procedure TFormRecord.Load(DataRecord: TRecord); 82 var 83 I: Integer; 84 NewLabel: TLabel; 85 NewControl: TControl; 86 CellRect: TRect; 87 begin 88 Row := DataRecord; 89 Controls.Clear; 90 Labels.Clear; 91 for I := 0 to Table.Fields.Count - 1 do begin 92 CellRect := Rect(10, 10 + I * 70, Panel1.Width - 20, (I + 1) * 70); 93 NewLabel := TLabel.Create(Panel1); 94 NewLabel.Caption := TField(Table.Fields[I]).TextBefore; 95 NewLabel.Parent := Panel1; 96 NewLabel.Left := CellRect.Left; 97 NewLabel.Top := CellRect.Top; 98 NewLabel.Visible := True; 99 Labels.Add(NewLabel); 100 case TField(Table.Fields[I]).FieldType of 101 ftString: begin 102 NewControl := TEdit.Create(Panel1); 103 NewControl.Parent := Panel1; 104 NewControl.Left := CellRect.Left; 105 NewControl.Top := CellRect.Top + NewLabel.Height + 6; 106 NewControl.Width := CellRect.Right - CellRect.Left; 107 NewControl.Visible := True; 108 TEdit(NewControl).Text := TValueString(Row.Values[I]).Value; 109 Controls.Add(NewControl); 110 end; 111 ftDateTime: begin 112 NewControl := TDateEdit.Create(Panel1); 113 NewControl.Parent := Panel1; 114 NewControl.Left := CellRect.Left; 115 NewControl.Top := CellRect.Top + NewLabel.Height + 6; 116 NewControl.Width := CellRect.Right - CellRect.Left; 117 NewControl.Visible := True; 118 TDateEdit(NewControl).Date := TValueDateTime(Row.Values[I]).Value; 119 Controls.Add(NewControl); 120 end; 121 end; 122 end; 123 end; 124 125 procedure TFormRecord.Save(DataRecord: TRecord); 126 var 127 I: Integer; 128 begin 129 for I := 0 to Table.Fields.Count - 1 do begin 130 case TField(Table.Fields[I]).FieldType of 131 ftString: TValueString(Row.Values[I]).Value := TEdit(Controls[I]).Text; 132 ftDateTime: TValueDateTime(Row.Values[I]).Value := TDateEdit(Controls[I]).Date; 133 end; 134 end; 135 end; 136 26 137 end. 27 138
Note:
See TracChangeset
for help on using the changeset viewer.