Changeset 8 for trunk/Forms/UFormEdit.pas
- Timestamp:
- Nov 14, 2012, 2:58:35 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormEdit.pas
r7 r8 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 Buttons, ExtCtrls ;9 Buttons, ExtCtrls, SpecializedList, SpecializedDictionary; 10 10 11 11 type 12 TControlType = (ctLabel, ctCheckBox, ctEdit, ctMemo, ctDate, ctTime, 13 ctComboBox); 14 15 TFormItem = class 16 Caption: string; 17 Name: string; 18 Visible: Boolean; 19 Rect: TRect; 20 ControlType: TControlType; 21 TitlePlacement: TAlign; 22 end; 23 24 { TFormItems } 25 26 TFormItems = class(TListObject) 27 function AddItem(Caption, Name: string; ControlType: TControlType; 28 Visible: Boolean; Rect: TRect): TFormItem; 29 end; 12 30 13 31 { TFormEdit } … … 18 36 ButtonCancel: TButton; 19 37 procedure FormCreate(Sender: TObject); 38 procedure FormDestroy(Sender: TObject); 20 39 private 21 40 { private declarations } 22 41 public 23 { public declarations } 42 RuntimeControls: TListObject; 43 FormItems: TFormItems; 44 Values: TDictionaryStringString; 45 procedure Update; 24 46 end; 25 47 … … 29 51 implementation 30 52 53 { TFormItems } 54 55 function TFormItems.AddItem(Caption, Name: string; ControlType: TControlType; 56 Visible: Boolean; Rect: TRect): TFormItem; 57 begin 58 Result := TFormItem.Create; 59 Result.Caption := Caption; 60 Result.Name := Name; 61 Result.Visible := Visible; 62 Result.Rect := Rect; 63 Result.ControlType := ControlType; 64 Add(Result); 65 end; 66 31 67 {$R *.lfm} 32 68 … … 35 71 procedure TFormEdit.FormCreate(Sender: TObject); 36 72 begin 73 FormItems := TFormItems.Create; 74 Values := TDictionaryStringString.Create; 75 RuntimeControls := TListObject.Create; 76 end; 37 77 78 procedure TFormEdit.FormDestroy(Sender: TObject); 79 begin 80 Values.Free; 81 RuntimeControls.Free; 82 FormItems.Free; 83 end; 84 85 procedure TFormEdit.Update; 86 var 87 NewControl: TControl; 88 I: Integer; 89 TitleRect: TRect; 90 const 91 W = 50; 92 H = 32; 93 begin 94 RuntimeControls.Clear; 95 for I := 0 to FormItems.Count - 1 do 96 with TFormItem(FormItems[I]) do begin 97 if TitlePlacement <> alNone then begin 98 NewControl := TLabel.Create(Self); 99 NewControl.Parent := Self; 100 NewControl.Caption := Caption; 101 TitleRect := Rect; 102 case TitlePlacement of 103 alLeft: TitleRect.Left := TitleRect.Left - 1; 104 alRight: TitleRect.Left := TitleRect.Left + 1; 105 alTop: TitleRect.Top := TitleRect.Top - 1; 106 alBottom: TitleRect.Top := TitleRect.Top + 1; 107 end; 108 NewControl.SetBounds(TitleRect.Left * W, TitleRect.Top * H, 109 (TitleRect.Right - TitleRect.Left) * W, (TitleRect.Bottom - TitleRect.Top) * H); 110 NewControl.Show; 111 end; 112 if ControlType = ctLabel then begin 113 NewControl := TLabel.Create(Self); 114 NewControl.Parent := Self; 115 NewControl.Caption := Values.Values[Name]; 116 NewControl.SetBounds(Rect.Left * W, Rect.Top * H, 117 (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H); 118 NewControl.Show; 119 end else 120 if ControlType = ctEdit then begin 121 NewControl.Show; 122 NewControl := TEdit.Create(Self); 123 TEdit(NewControl).Text := Values.Values[Name]; 124 NewControl.Parent := Self; 125 NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H, 126 (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H); 127 NewControl.Show; 128 end else 129 if ControlType = ctEdit then begin 130 NewControl := TMemo.Create(Self); 131 NewControl.Parent := Self; 132 TMemo(NewControl).Lines.Text := Values.Values[Name]; 133 NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H, 134 (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H); 135 NewControl.Show; 136 end else 137 if ControlType = ctCheckBox then begin 138 NewControl := TCheckBox.Create(Self); 139 NewControl.Parent := Self; 140 TCheckBox(NewControl).Enabled := Values.Values[Name] = '1'; 141 NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H, 142 (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H); 143 NewControl.Show; 144 end else 145 if ControlType = ctComboBox then begin 146 NewControl := TComboBox.Create(Self); 147 NewControl.Parent := Self; 148 TComboBox(NewControl).Text := Values.Values[Name]; 149 NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H, 150 (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H); 151 NewControl.Show; 152 end; 153 end; 38 154 end; 39 155
Note:
See TracChangeset
for help on using the changeset viewer.