![]() |
Re: nimmt meine zahlen nicht im stringgrid trotz strtoint
Es müsste dann so heissen:
Delphi-Quellcode:
oder um das Except wegzubekommen:
var a,b,c,d:integer;
procedure TForm2.Button1Click(Sender: TObject); begin try a := StrToInt(StringGrid1.Cells[0, 0]) ; b := StrToInt(StringGrid1.Cells[1, 0]) ; c := StrToInt(StringGrid1.Cells[2, 0]) ; d := StrToInt(StringGrid1.Cells[3, 0]) ; except on EConvertError do showmessage ('Ungültige Eingabe'); end;
Delphi-Quellcode:
So wird bei einem Fehler (keine Zahl eingegeben in der StringGrid-Zelle) -1 als Defaultwert zurückgegeben.
var a,b,c,d:integer;
procedure TForm2.Button1Click(Sender: TObject); begin a := StrToIntDef(StringGrid1.Cells[0, 0], -1) ; b := StrToIntDef(StringGrid1.Cells[1, 0], -1) ; c := StrToIntDef(StringGrid1.Cells[2, 0], -1) ; d := StrToIntDef(StringGrid1.Cells[3, 0], -1) ; If (a = -1) or (b = -1) or (c = -1) or (d = -1) then ShowMessage ('Ungültige Eingabe'); end; Wenn ein Feld -1 beinhaltet, dann kommt die Meldung. (Da geht natürlich nur, wenn die erlaubte Eingabe > -1 ist, also ab 0 positiv werdend... |
Re: nimmt meine zahlen nicht im stringgrid trotz strtoint
yep!
Danke Dir! |
Re: nimmt meine zahlen nicht im stringgrid trotz strtoint
Zitat:
Delphi-Quellcode:
(So wärst unabhängig von der Eingabe - aber auf die Eingabe von Nicht-Zahlen wird trotzdem geprüft...)
var a,b,c,d:integer;
procedure TForm2.Button1Click(Sender: TObject); begin If not TryStrToInt(StringGrid1.Cells[0, 0], a) or not TryStrToInt(StringGrid1.Cells[1, 0], b) or not TryStrToInt(StringGrid1.Cells[2, 0], c) or not TryStrToInt(StringGrid1.Cells[3, 0], d) then ShowMessage ('Ungültige Eingabe'); end; |
Re: nimmt meine zahlen nicht im stringgrid trotz strtoint
da wir jetzt beim Optimieren angekommen sind:
Eine Schleife (und ein Integer-Array) wären in diesem Fall wohl schon überlegenswert... |
Re: nimmt meine zahlen nicht im stringgrid trotz strtoint
@Helmi: TryStrToInt liefert im Erfolgsfall den Wert True!
Gruß Hawkeye |
Re: nimmt meine zahlen nicht im stringgrid trotz strtoint
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:50 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz