Autor Beitrag
Master_BB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 90



BeitragVerfasst: Mo 13.10.03 12:24 
Hya,
ich hab ein Prob und zwar klappt bei mir der Try Execpt block nicht.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm2.Edit2Exit(Sender: TObject);
var zahl:integer;
begin
 try
  zahl := StrToInt(Edit2.Text);
 except
  on EConvertError do
   begin
    ShowMessage('Sie müssen die Nummer des Faches eingeben!'
    +'Die Nummer steht obem im Anzeigefeld.');
    Edit2.Text := '';
   end;
 end;
end;


in einem Editfelt wird also eine Integerzahl eingegeben und wenn dem nicht so ist wird halt die message ausgegeben. Jedoch kommt trotz eigentlichen abfangen des EConvertErrors der Fehler (EConvertError).
Warum das?? fange den doch ab.
[/code]
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: Mo 13.10.03 12:48 
ausblenden Delphi-Quelltext
1:
on EConvertError do					

die zeile kannst du dir doch sparen!
wenn das einlesen schief geht kommt der execpt block dran. da es nicht mehr fehlerursachen geben kann, kannst du dir das ConvertError dir sparen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm2.Edit2Exit(Sender: TObject); 
var zahl:integer; 
begin 
 try 
  zahl := StrToInt(Edit2.Text); 
 except 
    ShowMessage('Sie müssen die Nummer des Faches eingeben!' 
    +'Die Nummer steht obem im Anzeigefeld.'); 
    Edit2.Text := ''
 end
end;

so müsste es funktionieren

_________________
Patrick
im zweifelsfall immer das richtige tun!!!
Master_BB Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 90



BeitragVerfasst: Mo 13.10.03 13:09 
ja so hatte ich es vorher und da gings nicht da dachte ich mir das wenn ich es konkretisiere mit on EConvertError den Fehler zu umgehen aber ging nicht.
das von dir klappt auch nicht.
Muß ich noch irgenteine Unit dazu einfügen? damit ich try-except blöcke einbaun kann
Simon Joker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236
Erhaltene Danke: 1



BeitragVerfasst: Mo 13.10.03 13:18 
Hi Master_BB

hast du mal getestet, ob die Fehlermeldung auch erscheint, wenn due das Programm ohne IDE startest (also nicht F9 ect.)? Wenn nicht hast du die Sprachexceptions aktiviert (Debuggeroptionen). Abschalten, dann funzt es auch in der IDE.
Master_BB Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 90



BeitragVerfasst: Mo 13.10.03 13:28 
Stimmt Simon Joker wenn ide die Projekt1.exe compilieren lasse und dann so ausführe funktioniert der Try-Except Block.
mal kukn wie ich diese Sprachexceptions aus mache.
THX schon mal
Simon Joker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236
Erhaltene Danke: 1



BeitragVerfasst: Mo 13.10.03 13:49 
Tools -> Debugger-Optionen -> Sprach-Exceptions -> Bei Delphi-Exceptions stoppen Häkchen wegmachen
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: Di 14.10.03 09:22 
an die möglichkeiti hab ich mal wieder nicht gedacht :autsch:

_________________
Patrick
im zweifelsfall immer das richtige tun!!!