1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
| procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); var e: TEdit; c : char; s : string; p, p1 : integer; begin e := Sender as TEdit; s := e.Text+#0; if not (Key in [#8, #13, #27, '0'..'9', ',', '+', '-']) then Key := #0; if Key = ',' then begin p := e.SelStart+1; p1 := Pos(Key, e.Text); if p1>0 then begin e.Text := Copy(e.Text,1,p1-1)+Copy(e.Text,p1+1,255); e.Text := Copy(e.Text,1,p-1) +','+Copy(e.Text,p+1,255); Key := #0; e.SelStart := p-1; end; end; if Key in ['+', '-'] then begin p := e.SelStart+1; c := s[1]; if c in ['+','-'] then e.Text := Copy(e.Text,2,255); e.Text := Key + e.Text; Key := #0; e.SelStart := p; end; if Key = #27 then e.Text := ''; if Key = #13 then Label1.Caption := FormatFloat('0.#######', StrToFloat(e.Text)); end; |