Autor Beitrag
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Di 26.10.04 17:15 
Ich will die Zahl am ende eines Strings haben. Das Problem ist das die Zahl auch mehrstellig sein kann. Darum hab ich folgenden Code gemacht.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  Zeichen:=0;
  Weiter:=true;
  while Weiter=true do
  begin
    try Zahl:=StrToInt(copy(Memo1.Lines[0],length(Memo1.Lines[0])-Zeichen,length(Memo1.Lines[0])))
    except
      Weiter:=false;
    end;
    inc(Zeichen);
  end;
  Label1.Caption:=IntToStr(Zahl);

Der Funktioniert auch ganz gut wenn man ihn auserhalb von Delphi startet, doch wenn man ihn in Delphi started kommt die Meldung das der Buchstabe nicht in Integer umgewandelt werden kann, obwohl das ja absichtlich ist und von der try except schleife abgefangen wird.
Wie kann ich diese Fehlermeldung abstellen? Oder kann ich das sogar 'besser' programmieren?
greg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119

Windows2000, WindowsXP
D5 Prof
BeitragVerfasst: Di 26.10.04 17:28 
Hallo Coder,

unter [Tools] -> [Debugger-Optionen] Reiter [Sprach-Exceptions] kannst Du die Exception eintragen, die Du während des Debuggens nicht gemeldet haben möchtest. Dafür musst Du Dir die Fehlermeldung genau ansehen.

Es geht sicher auch etwas eleganter. Steht in Deinem String von rechts aus gesehen neben der Zahl ein bestimmtes Zeichen? z.B. ein Leerzeichen? Dann fängst Du von rechts an nach diesem bestimmten Zeichen zu suchen und hängst alles was Du findest auf einen HilfsString
ausblenden Delphi-Quelltext
1:
HilfsString := String[Position] + HilfsString;					

Wenn Du jetzt Dein evtl. vorhandenes Trennzeichen gefunden hast, wandelst Du den HilfsString mit StrToInt um.

Gruß
Gregor
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Di 26.10.04 17:28 
wenn jemand sagen kann iwe mans abstellt wäre gut, weiß ich auch noch net

aber für dich: ich nehme immer strtointdef
greg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119

Windows2000, WindowsXP
D5 Prof
BeitragVerfasst: Di 26.10.04 17:38 
... ich hab nachgesehen ...
Die Sprach-Exception ist vom Typ EConvertError.

Gruß
Gregor
Coder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Di 26.10.04 17:49 
Habs rausgefunden! :idea:
Tools > Debugger-Optionen > Sprach-Exeptions > Bei Delphi Exeptions stoppen
Wenn da der Hacken weg ist, meckert er nicht mehr. :wink:
greg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119

Windows2000, WindowsXP
D5 Prof
BeitragVerfasst: Di 26.10.04 18:01 
komisch ... ich muss einen Haken setzen, damit Delphi nicht meggert ... vielleicht von Version zu Version wieder unterschiedlich? Ich hab Delphi 5

Gregor
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Di 26.10.04 18:09 
nene bei mir war kein häkchen -> trotzdem excpetion
dann häkchen gemacht -> immer noch exception
dann wieder weg gemacht -> keine excpetion

is wohl nen delphi bug,
greg ach mal das häkchen weg uznd schau ob du ne exception bekommst (solltest eigentlich net)
Coder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Di 26.10.04 18:15 
Bei mir ist der Hacken weg. Delphi 7 :gruebel:
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Di 26.10.04 18:20 
wie gesagt bei mir war der auch nie da und habe immer fehlermedlungen bekommen
dann hab ich den einmal wieder hingemacht und wieder fehlermeldung dann wieder weg und nu gehts ohne die meldungen

denk mal delphi checkt das irgendwie nicht, man muss den erst einaml setzen und dann wieder wegmachen damit die msg net mehr kommen