Autor Beitrag
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Mi 16.01.08 19:28 
Hi zusammen!

Dieser Quelltext funktioniert nicht :(, und zwar in Zeile 4: Inkompatible Typen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
  If E = EOverflow then // hier
  Application.MessageBox ('Gleitkommaüberlauf. Bitte verkleinern Sie ihre Zahl.''Rechner', MB_OK+MB_ICONHAND)
  Else
  Begin
  Application.MessageBox('Diese Exception wurde vom Programmierer noch nicht implementiert. Melden Sie folgende Fehlermeldung:''Rechner', MB_OK + MB_ICONHAND);
  Application.ShowException(E);
end;


Da das ja nicht zu funktionieren scheint, wollte ich fragen: Wie kann ich auf abgefangene Exceptions (Wegen dem ApplicatioEvents :wink:) im Nachhinein mit If reagieren?

ausblenden Delphi-Quelltext
1:
Case geht auch nicht!					

_________________
Die Lösung ist nicht siebzehn.
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Mi 16.01.08 19:34 
Hab's!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
  If String (E) = EOverflow then // In String konvertieren
  Application.MessageBox ('Gleitkommaüberlauf. Bitte verkleinern Sie ihre Zahl.''Rechner', MB_OK+MB_ICONHAND)
  Else
  Begin
  Application.MessageBox('Diese Exception wurde vom Programmierer noch nicht implementiert. Melden Sie folgende Fehlermeldung:''Rechner', MB_OK + MB_ICONHAND);
  Application.ShowException(E);
end;


Ist allerdings nicht gerade elegant... :crying:

_________________
Die Lösung ist nicht siebzehn.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mi 16.01.08 19:59 
Wie wäre es, wenn du einfach den Klassentyp abfragst? Zum Beispiel mit E.ClassType... Eine Exception ist nämlich auch eine Klasse mit den Klassenmethoden.
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Mi 16.01.08 20:59 
Also so :? ?

ausblenden Delphi-Quelltext
1:
If E.Classname = EOverflow then {...}					

_________________
Die Lösung ist nicht siebzehn.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mi 16.01.08 21:14 
Jep, genau so. Das funktioniert doch, oder?
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mi 16.01.08 21:31 
Wäre dann nicht die "schönere" Lösung
ausblenden Delphi-Quelltext
1:
if E is EOverflow then ...					

?
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mi 16.01.08 22:04 
Ich arbeite eher weniger mit is und as, aber natürlich ist das noch schöner :zustimm:

Ich persönlich finde andere Möglichkeiten zur Lösung übersichtlicher. Zum Beispiel verwende ich TObject(Instance) statt Instance as TObject.
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Do 17.01.08 15:57 
Titel: OffTopic
Obwohl wir jetzt OffTopic werden: Welchen Sinn haben is und as? :?!?:

_________________
Die Lösung ist nicht siebzehn.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Do 17.01.08 17:26 
Sie erhöhen zumindest mal die Lesbarkeit! Objekt as klasse ist einfacher zu lesen als der typecast Klasse (Objekt) finde ich.
(Vgl. Ruby : 5.times do macht das selbe wie for i := 1 to 5 do in Delphi. Da ist Ruby lesbarer ;) (trotzdem mag ich ruby nicht.))

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.