Autor Beitrag
DieNase
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mo 26.09.05 10:47 
Moin,

ich habe ein kleines Problem mit meinen Editfeldern.
Es sollen nur Zahlen eingegeben werden und das klappt auch wunderbar, allerdings wenn ich mich vertippe dann kann ich nicht mit der Backspace Taste korrigieren, sondern nur mit Entf.

Hier mal der Code dazu, vielleicht kann mir ja jemand helfen....gibt es da ein except oder so?


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.E_BreiteLadungstraegerKeyPress(Sender: TObject; var Key: Char);
begin
    if (Key < '0') or (Key > '9') then Key :=Chr(27)
end;



Danke schonmal

Michael

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconChristian S.: Topic aus Algorithmen, Optimierung und Assembler verschoben am Mo 26.09.2005 um 11:50
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Mo 26.09.05 11:06 
ausblenden Delphi-Quelltext
1:
2:
3:
begin
  if not (Key in ['0'..'9', #8]) then Key:=#0;
end;

Allerdings kann man durch Copy&Paste immer noch Text in die Zelle schreiben!

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
DieNase Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mo 26.09.05 12:26 
Danke, das ist schon super.

kann ich das mit dem Text noch sperren? Ich ändere nachher die Werte ja alle in Integer um...kann ich da vieleicht dann eine Showmessage kommen lassen

Michael
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Mo 26.09.05 13:05 
Im OnExit-Event kanns du die eingegbenen Zeichen nochmals filtern:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Edit1Exit(Sender: TObject);
var
  s: string;
  i: integer;
begin
  s:='';
  for i:=0 to Length(Edit1.Text)-1 do
    if Edit1.Text[i] in ['0'..'9']
      then s:=s+Edit1.Text[i];
  Edit1.Text:=IntToStr(StrToInt(s));
end;

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!