Autor Beitrag
kongreddgrass
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 238

Win 98, Win 2000, Win Xp Prof.,Linux 8.2 Prof
Delphi 6
BeitragVerfasst: Mo 25.02.08 22:04 
Hallo,
ich programmiere ein Proggi, darin befindet sich ein zur Eingabe gedachtes Edit das bei Ausführung die Werte je für Label1 und Label2 mit 5 bzw. 15 multipliziert.
Das Eingabefeld (Edit1) wurde als espezial umbenannt
eingabespezial, abwehr, angriff sind Integer.
attspezial ist ein Label.
Das Problem bei mir ist, dass Delphi mit einer Meldung stoppt und mir sagt dass,
"" is not a valid integer value

Edit: Der Compliler stoppt deshalb wegen dem leeren Edit-Feld und kann somit keine Zahl umwandeln.

Wenn ich in das Edit-Feld eine Zahl eingebe, soll ohne dass ich eine Enter-Taste drücke, das Ergebnis beim Label ausgegeben werden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.espezialEnter(Sender: TObject);
var
eingabespezial,abwehr,angriff:integer;
begin
        eingabespezial:=strtoint(espezial.Text);
        abwehr:=eingabespezial * 5;
        angriff:=eingabespezial * 15;
        aspezial.caption:=(inttostr(abwehr));
        attspezial.caption:=(inttostr(angriff));
end;



Moderiert von user profile iconChristian S.: Quote- durch Delphi-Tags ersetzt
Moderiert von user profile iconChristian S.: Topic aus Windows API verschoben am Mo 25.02.2008 um 22:09

_________________
o.o


Zuletzt bearbeitet von kongreddgrass am Fr 29.02.08 10:46, insgesamt 1-mal bearbeitet
blaskito
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Win2003, 2008, 2012, WinXP, Win7
Delphi 6 Pers.
BeitragVerfasst: Mo 25.02.08 22:48 
Hi,

ich gehe mal davon aus, dass dein Edit leer ist. Betrittst du dann das Feld soll "leer" dann in Integer umgewandelt werden ... daher der Fehler.

Gruß aus dem Norden
blaskito
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mo 25.02.08 23:00 
Bist du sicher, dass du das richtige Event ausgesucht hast?
OnEnter bedeutet nicht, dass es ausgelöst wird, wenn man Enter drückt, sondern wenn das Eingabefeld den focus erhält.
kongreddgrass Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 238

Win 98, Win 2000, Win Xp Prof.,Linux 8.2 Prof
Delphi 6
BeitragVerfasst: Do 28.02.08 19:29 
hm ich denke weil das Edit feld leer ist. Deswegen auch der Fehler
nur wie setze ich das richtig um.
wenn ich Edit1.Text:='0'; definiere dann egal welche zahl ich eingebe steht dann 10 oder 20 da :(

_________________
o.o
kongreddgrass Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 238

Win 98, Win 2000, Win Xp Prof.,Linux 8.2 Prof
Delphi 6
BeitragVerfasst: Fr 29.02.08 10:48 
ich hab mein Problem oben wenig umgeschrieben bzw. was dazugeschrieben. Ich habs bissal blöd geschrieben!

_________________
o.o
Agawain
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 460

win xp
D5, MySQL, devxpress
BeitragVerfasst: Fr 29.02.08 10:55 
hi

Benutz das onChange Ereignis oder onExit, wenn die Benutzereingabe erst verarbeitet werden soll, wenn der Benutzer das Edit-feld verläßt

_________________
Gruß Aga
kongreddgrass Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 238

Win 98, Win 2000, Win Xp Prof.,Linux 8.2 Prof
Delphi 6
BeitragVerfasst: Fr 29.02.08 10:58 
ok danke das klappt jetzt wunderbar. :D
Nur wenn ich die Löschtaste drücke weil z.B. die Zahl falsch eingegeben war, dann ist der Wert wieder keiner und der Compiler stoppt.

_________________
o.o
Nico72
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Win XP, Vista
Delphi 7, Delphi 2006
BeitragVerfasst: Fr 29.02.08 11:00 
Hallo,

du berechnest deine Werte immer noch im OnEnter-Event.

user profile iconXentar hat folgendes geschrieben:
Bist du sicher, dass du das richtige Event ausgesucht hast?
OnEnter bedeutet nicht, dass es ausgelöst wird, wenn man Enter drückt, sondern wenn das Eingabefeld den focus erhält.


Ausserdem ist eine Umwandlung eines vom User eingegebenen Textes in ein Integer mit StrToIntDef sicherer, da dann bei fehlender oder falscher Eingabe keine Exception ausgelöst wird.

zu spät...
naja teilweise..
kongreddgrass Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 238

Win 98, Win 2000, Win Xp Prof.,Linux 8.2 Prof
Delphi 6
BeitragVerfasst: Fr 29.02.08 11:14 
des heisst dann so oder?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.espezialChange(Sender: TObject);
var
eingabespezial,abwehr,angriff:integer;
spezialstr:String;
begin
        spezialstr:=(espezial.Text);
        eingabespezial:=StrToIntDef(spezialstr);
        abwehr:=eingabespezial * 5;
        angriff:=eingabespezial * 15;
        aspezial.caption:=(inttostr(abwehr));
        attspezial.caption:=(inttostr(angriff));

end;


aber da gibt er schon vorm compilen ne fehlermeldung aus.
Ich checks ned ^^ ich war schon jahre nicht mehr an delphi ohmann^^

_________________
o.o
Nico72
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Win XP, Vista
Delphi 7, Delphi 2006
BeitragVerfasst: Fr 29.02.08 11:20 
In meiner Delphi-Hilfe steht folgendes:

Syntax
[Delphi] function StrToIntDef(const S: string; Default: Integer): Integer;

Beschreibung
StrToIntDef konvertiert den in S angegebenen String in einen Integer-Wert. S muss die Entsprechung eines ganzzahligen Wertes (dezimal oder hexadezimal) sein. Enthält S keine gültige Zahl, gibt StrToIntDef Default zurück.

Das bedeutet, du hast einen Parameter in StrToIntDef vergessen, nämlich den Defaultwert, der zurückgegeben wird, falls kein gülter Integerwert im String steht.
kongreddgrass Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 238

Win 98, Win 2000, Win Xp Prof.,Linux 8.2 Prof
Delphi 6
BeitragVerfasst: Fr 29.02.08 12:01 
geil danke Leute! Ich bin stolz auf euch! :D jetzt klappts 8)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.espezialChange(Sender: TObject);
var
eingabespezial,abwehr,angriff:integer;
spezialstr:String;
begin
        spezialstr:=(espezial.Text);
        eingabespezial:=StrToIntDef(spezialstr, 0);
        abwehr:=eingabespezial * 5;
        angriff:=eingabespezial * 15;
        aspezial.caption:=(inttostr(abwehr));
        attspezial.caption:=(inttostr(angriff));

end;


dann markiere ich den Thread als gelöst :wink:

_________________
o.o