Autor Beitrag
Roadrunner116
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 89

Win XP Home, Ubuntu Linux 6.06
Delphi 7, Java, PHP
BeitragVerfasst: Sa 27.01.07 16:15 
Hallo Leute,
wie kann man die Eingabe in eienem Edit daraufhin überprüfen, ob es eine zahl oder ein text ist?

Gruß Roadrunner116
Saubäär
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 376



BeitragVerfasst: Sa 27.01.07 16:23 
Hi Roadrunner,

z.B. so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
function IsInt(Check: String): Boolean;
begin
 try
  StrToInt(Check);
  Result := True;
 except
  Result := False;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if IsInt(Edit1.Text) = True then
  ShowMessage('Ja Integer')
 else
  ShowMessage('Nein kein Integer'); 
end;


Wenn du das Programm aus der IDE startest kommt eine Fehlermeldung von Delphi. Startest du das Programm aber 'extern', bekommst du die ShowMessage.

Gruß

Saubäär
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 27.01.07 16:27 
Besser ist aber:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if TryStrToInt(Edit1.Text, Val) then
  ShowMessage('Zahl')
else
  Showmessage('Keine Zahl');

(Val ist eine Variable vom Typ Integer)

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Roadrunner116 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 89

Win XP Home, Ubuntu Linux 6.06
Delphi 7, Java, PHP
BeitragVerfasst: Sa 27.01.07 16:36 
Danke dir, funktioniert!
Roadrunner116 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 89

Win XP Home, Ubuntu Linux 6.06
Delphi 7, Java, PHP
BeitragVerfasst: Sa 27.01.07 16:37 
@GTA-Place: Das werde ich gleich auch einmal testen...
Roadrunner116 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 89

Win XP Home, Ubuntu Linux 6.06
Delphi 7, Java, PHP
BeitragVerfasst: Sa 27.01.07 16:42 
funktioniert auch, sogar über [F9] aus Delphi heraus!
un is weniger quelltext....

Danke
Gruß Roadrunner116
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 27.01.07 17:05 
Noch besser wäre aber gleich zu verhindern, dass der Benutzer was anderes als eine Zahl einträgt. Das kannst du im OnKeyDown/OnKeyPress prüfen.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)