AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls Delphi nimmt meine zahlen nicht im stringgrid trotz strtoint
Thema durchsuchen
Ansicht
Themen-Optionen

nimmt meine zahlen nicht im stringgrid trotz strtoint

Ein Thema von Molzer · begonnen am 1. Jan 2009 · letzter Beitrag vom 1. Jan 2009
Antwort Antwort
Seite 3 von 3     123   
Benutzerbild von Helmi
Helmi

Registriert seit: 29. Dez 2003
Ort: Erding, Republik Bayern
3.312 Beiträge
 
Delphi XE2 Professional
 
#21

Re: nimmt meine zahlen nicht im stringgrid trotz strtoint

  Alt 1. Jan 2009, 17:13
Es müsste dann so heissen:

Delphi-Quellcode:
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;
oder um das Except wegzubekommen:
Delphi-Quellcode:
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;
So wird bei einem Fehler (keine Zahl eingegeben in der StringGrid-Zelle) -1 als Defaultwert zurückgegeben.
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...
mfg
Helmi

>> Theorie ist Wissen, dass nicht funktioniert - Praxis ist, wenn alles funktioniert und keiner weiss warum! <<
  Mit Zitat antworten Zitat
Molzer

Registriert seit: 7. Dez 2008
70 Beiträge
 
#22

Re: nimmt meine zahlen nicht im stringgrid trotz strtoint

  Alt 1. Jan 2009, 17:15
yep!

Danke Dir!
  Mit Zitat antworten Zitat
Benutzerbild von Helmi
Helmi

Registriert seit: 29. Dez 2003
Ort: Erding, Republik Bayern
3.312 Beiträge
 
Delphi XE2 Professional
 
#23

Re: nimmt meine zahlen nicht im stringgrid trotz strtoint

  Alt 1. Jan 2009, 17:16
Zitat von Helmi:
Es müsste dann so heissen:

Delphi-Quellcode:
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;
oder um das Except wegzubekommen:
Delphi-Quellcode:
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;
So wird bei einem Fehler (keine Zahl eingegeben in der StringGrid-Zelle) -1 als Defaultwert zurückgegeben.
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...
Oder:
Delphi-Quellcode:
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;
(So wärst unabhängig von der Eingabe - aber auf die Eingabe von Nicht-Zahlen wird trotzdem geprüft...)
mfg
Helmi

>> Theorie ist Wissen, dass nicht funktioniert - Praxis ist, wenn alles funktioniert und keiner weiss warum! <<
  Mit Zitat antworten Zitat
taaktaak

Registriert seit: 25. Okt 2007
Ort: Radbruch
1.990 Beiträge
 
Delphi 7 Professional
 
#24

Re: nimmt meine zahlen nicht im stringgrid trotz strtoint

  Alt 1. Jan 2009, 17:19
da wir jetzt beim Optimieren angekommen sind:
Eine Schleife (und ein Integer-Array) wären in diesem Fall wohl schon überlegenswert...
Ralph
  Mit Zitat antworten Zitat
Hawkeye219

Registriert seit: 18. Feb 2006
Ort: Stolberg
2.227 Beiträge
 
Delphi 2010 Professional
 
#25

Re: nimmt meine zahlen nicht im stringgrid trotz strtoint

  Alt 1. Jan 2009, 18:38
@Helmi: TryStrToInt liefert im Erfolgsfall den Wert True!

Gruß Hawkeye
  Mit Zitat antworten Zitat
Benutzerbild von Helmi
Helmi

Registriert seit: 29. Dez 2003
Ort: Erding, Republik Bayern
3.312 Beiträge
 
Delphi XE2 Professional
 
#26

Re: nimmt meine zahlen nicht im stringgrid trotz strtoint

  Alt 1. Jan 2009, 18:44
Zitat von Hawkeye219:
@Helmi: TryStrToInt liefert im Erfolgsfall den Wert True!

Gruß Hawkeye
Danke - habs repariert
mfg
Helmi

>> Theorie ist Wissen, dass nicht funktioniert - Praxis ist, wenn alles funktioniert und keiner weiss warum! <<
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 3 von 3     123   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:49 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz