Autor Beitrag
Becks16
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 405



BeitragVerfasst: Do 13.01.05 11:42 
Ich habe eine Editfeld wo ich eine Zahl eingebe und dann soll er im StringGrid so viels zeilen machen wie ich oben eingeben. Klappt so weit auch dann will ich das editfeld mit backspace leeren und dann kommt eine fehler Meldung
"ist kein gültiger Integerwert"

das hier ist mein Quelltext

ausblenden Delphi-Quelltext
1:
2:
if ((Key<'0') or (Key>'9')) and (Key<>#8) then
    Key := #0; //hier hab ich ihn gesagt das nur die tasten von 0 bis 9 erlaubt sind und backspace


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Ich bin Dumm und weiss nichts :-)
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: Do 13.01.05 11:45 
Das hat mit der obigen Routine nichts zu tun.
Ich vermute mal, dass du im OnChange des Edit-Feldes ein StrToInt machst. Wenn dein Edit-Feld aber leer ist, dürftest du genau diese Fehlermeldung bekommen.
Becks16 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 405



BeitragVerfasst: Do 13.01.05 11:51 
Genau bei OnChange habe ich StrToInt gemacht. Und nun wie muss ich jetzt vorgehen ???

_________________
Ich bin Dumm und weiss nichts :-)
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 13.01.05 11:57 
Delphi-Hilfe:
Die Funktion konvertiert einen String, der ein Integer repräsentiert (in dezimaler oder hexadezimaler Form), in eine Zahl. Dabei gelten Voreinstellungen für den Fehlerfall.

Unit
SysUtils

Kategorie
Typumwandlung

Delphi-Syntax
ausblenden Delphi-Quelltext
1:
function StrToIntDef(const S: string; const Default: Integer): Integer;					


Beschreibung
StrToIntDef konvertiert konvertiert den String S, der eine Integer repräsentiert (in dezimaler oder hexadezimaler Form), in eine Zahl. Enthält S keine gültige Zahl, gibt StrToIntDef Default zurück.
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: Do 13.01.05 11:58 
Vor dem StrToInt prüfen, ob dein Edit-Feld leer ist. Ist es leer, kannst du deinen Wert für deine Liste einfach auf "0" setzen. Wenn nicht leer, dann StrToInt.
Also eine ganz einfach if .. then .. else .. - Sache.
Becks16 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 405



BeitragVerfasst: Do 13.01.05 12:04 
ja das klappt so weit jasocul aber nun habe ich da immer eine null drine stehen und bekomme die mit backspace auch nicht mehr weg

_________________
Ich bin Dumm und weiss nichts :-)
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 13.01.05 12:07 
Du hast doch gesagt das du nur Zahlen in dem Editfeld haben möchtest. ;-)
Becks16 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 405



BeitragVerfasst: Do 13.01.05 12:11 
jetzt seh ich gar nicht mehr durch tino. Ich kann ja auch nur zahlen eingeben. Wenn ich z.b. eine 2 eingeben und sie mit Backspace weg mache dann kommt eine Fehlermeldung. Ich habe es dann so gemacht wie jasocul gesagt hat aber jetzt steht dann immer eine 0 mit drinne

_________________
Ich bin Dumm und weiss nichts :-)
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: Do 13.01.05 12:13 
Dann hast du vermutlich die "0" in dein Edit-Feld geschrieben. Das ist doch gar nicht notwendig.
Im OnChange:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  Zaehler : Integer;
begin
  if edit1.text = '' then
    Zaehler := 0
  else
    Zaehler := IntToStr(edit1.text);
end;

Wobei Zaehler deine Variable für das Setzen in deiner Liste wäre.
Becks16 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 405



BeitragVerfasst: Do 13.01.05 12:59 
Das klappt nicht

Das hier ist mein Quelltext

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Tf_namenmanager.edit_anzahlChange(Sender: TObject);
var  
  Zaehler : Integer;  
begin
//if edit_anzahl.Text='' then edit_anzahl.Text:='0';
   StringGrid1.RowCount:=StrtoInt(edit_anzahl.Text)+1;
  if edit_anzahl.text = '' then  
    Zaehler := 0  
  else  
     Zaehler := StrtoInt(edit_anzahl.text);
        end;


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Ich bin Dumm und weiss nichts :-)
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: Do 13.01.05 13:11 
Becks16 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Tf_namenmanager.edit_anzahlChange(Sender: TObject);
var  
  Zaehler : Integer;  
begin
//if edit_anzahl.Text='' then edit_anzahl.Text:='0';
   StringGrid1.RowCount:=StrtoInt(edit_anzahl.Text)+1;
  if edit_anzahl.text = '' then  
    Zaehler := 0  
  else  
     Zaehler := StrtoInt(edit_anzahl.text);
        end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure Tf_namenmanager.edit_anzahlChange(Sender: TObject);
begin
  if edit_anzahl.text = '' then  
    StringGrid1.RowCount := 1 // 0 ist hier Blödsinn
  else  
   StringGrid1.RowCount:=StrtoInt(edit_anzahl.Text)+1;
  end;

Die Variable Zaehler hatt ich doch nur eingeführt, da ich deine echte Zuweisung nicht kannte.
Becks16 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 405



BeitragVerfasst: Do 13.01.05 13:13 
Danke Schön es hat endlich geklappt

_________________
Ich bin Dumm und weiss nichts :-)