Autor Beitrag
150gozilla
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 37

Windows XP Pro
Delphi5 Pro
BeitragVerfasst: Mi 31.08.05 08:30 
Hallo liebe user.

Ich programmiere grad ein Rechenprogramm.

Nun ist folgendes problem.

Ich will nicht das der Benutz dieses Programmes, in das editfeld (wo der Wert eingegeben wird) Buchstaben eingeben kann.

Wie kann ich das verhindern, das man in das Editfeld keine Buchstaben reinschreiben kann ?


Moderiert von user profile iconGausi: Topic aus Off Topic verschoben am Mi 31.08.2005 um 09:36
chrissivo
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 130

WIN XP, WIN 2000, WIN MCE, WIN 98
D5 Pers
BeitragVerfasst: Mi 31.08.05 08:33 
Du könntest das entweder prüfen, indem du beim OnKeyDown-Ereignis überprüft, ob der Key in Bereich ['0'..'9'] liegt, oder du nimmst ein MaskEdit-Feld und erstellst eine EditMask in die du Neunen einträgst.
Schau am besten mal in der Delphi-Hilfe unter EditMask nach. Dort steht drin, wie du diese belegen kannst.
Viele Grüße

Chrissi

_________________
"... was ich noch zu sagen hätte dauert eine Zigarette, und ein letztes Glas im Steh'n..."
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 31.08.05 08:49 
@150gozilla:
Wenn du hier mal im Forum suchst, wirst du noch viele andere Lösungsansätze mit Source-Beispielen finden. :wink:
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mi 31.08.05 08:53 
(Wie kann ich das verhindern, das man in das Editfeld keine Buchstaben reinschreiben kann ?)

Man kann in ein Edit Buchstaben eingeben !
Aber das war bestimmt nur schlecht formuliert - Spass
Nur Zahlen und Komma zulassen.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in [#8, #9, #44, #48 .. #57]) then key:=#0;
end;
ManuelGS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 173

Win XP HE, Suse Linux
D6, D7, D2005 Personal
BeitragVerfasst: Mi 31.08.05 10:04 
@blackheart
das ist kein guter lösungsansatz:
es gibt copy & paste.

_________________
"Leben ist gänzlich Bühne und Spiel; so lerne denn spielen
und entsage dem Ernst - oder erdulde das Leid." - Palladas von Alexandria
150gozilla Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 37

Windows XP Pro
Delphi5 Pro
BeitragVerfasst: Mi 31.08.05 12:58 
user profile iconBlackheart666 hat folgendes geschrieben:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in [#8, #9, #44, #48 .. #57]) then key:=#0;
end;


Gibts auch ne möglichkeit, das man nur zahlen und punkte "." zulassen kann? Programmiere was mit ip, deswegen
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mi 31.08.05 13:01 
user profile icon150gozilla hat folgendes geschrieben:
user profile iconBlackheart666 hat folgendes geschrieben:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in [#8, #9, #44, #48 .. #57]) then key:=#0;
end;


Gibts auch ne möglichkeit, das man nur zahlen und punkte "." zulassen kann? Programmiere was mit ip, deswegen


[x] Du hast nicht verstanden, was diese Zeile Code tut.

Du kannst auch nur Zahlen und € zulassen oder welche Zeichen auch immer, musst nur die richtigen Zeichencodes in die Überprüfung einschließen.

_________________
Bravery calls my name in the sound of the wind in the night...
Amateur
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 777

(Win98, WinMe) WinXP Prof
D3 Prof, D6 Pers, D2k5 Pers., Turbo C++ Explorer
BeitragVerfasst: Mi 31.08.05 13:08 
könnte man net wegen copy paste und so noch ne zeile irgendwo rein setzen zum beispiel in onchange das überprüft ob der text nur aus nummern und so besteht wenn der text nicht '' ist?
zum beispiel if not edit1.text = '' then for i:=1 to length(edit1.text) do begin s:=edit1.text;
if not s[i] in alphabet then s[i]:='';end;

und alphabet is nen set der zeichen die erlaubt sind... ginge das net so irgendwie? sry. is nur pseudocode oder wie auch immer man das nennt... hab ich mir grad mal so ausgedacht

_________________
"Kein dummes Gerede. Kein Rumrätseln. Denkt an nichts anderes mehr, nur noch an das, was vor euch liegt. Das ist die wahre Herausforderung. Ihr müßt euch vor euch selbst schützen, Leute." (Rennes in "Cube")
Beiträge: >700
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mi 31.08.05 13:11 
Klar, geht auch sowas. Würde ich zusätzlich auch auf jeden Fall machen.

Wenn sichs um Zahlen dreht, kann man da auch einfach innerhalb try..except ne Konvertierung durchführen und im Except dann die Meldung werfen udn das Feld fokussieren.

_________________
Bravery calls my name in the sound of the wind in the night...
Grendel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 443

Gentoo Linux, MacOS X, Win 2000
D5 Ent, D7 Ent, Lazarus, Anjuta, MonoDevelop
BeitragVerfasst: Mi 31.08.05 13:14 
user profile iconnoidic hat folgendes geschrieben:
Wenn sichs um Zahlen dreht, kann man da auch einfach innerhalb try..except ne Konvertierung durchführen und im Except dann die Meldung werfen udn das Feld fokussieren.

Herr Kollege, ich bitte sie :)
Noch nie was von "TryStrToInt()" gehört?! Ist imho wesentlich eleganter als eine Konvertierung per try..except einzuschließen.

Bis neulich ...
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mi 31.08.05 13:20 
Macht aber auch nix anderes, von daher..

_________________
Bravery calls my name in the sound of the wind in the night...
Amateur
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 777

(Win98, WinMe) WinXP Prof
D3 Prof, D6 Pers, D2k5 Pers., Turbo C++ Explorer
BeitragVerfasst: Mi 31.08.05 13:27 
theoretisch is onchange imemr aktiviert sobald man was am text im edit ändert oder? dann sollte meine solution doch reichen... wird immer der string überprüft..
trystrtoint kenn ich net weiß net was das macht... wenn das aber so funzt wie meine solution dann is das natürlich noch besser
naja gibt ja genug lösungen muss der threadersteller ma posten was funzt und was er genommen hat

_________________
"Kein dummes Gerede. Kein Rumrätseln. Denkt an nichts anderes mehr, nur noch an das, was vor euch liegt. Das ist die wahre Herausforderung. Ihr müßt euch vor euch selbst schützen, Leute." (Rennes in "Cube")
Beiträge: >700
ManuelGS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 173

Win XP HE, Suse Linux
D6, D7, D2005 Personal
BeitragVerfasst: Mi 31.08.05 13:34 
(Fast) alle Wege führen nach Rom!! :)

_________________
"Leben ist gänzlich Bühne und Spiel; so lerne denn spielen
und entsage dem Ernst - oder erdulde das Leid." - Palladas von Alexandria