Autor Beitrag
Mindforce
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Sa 10.06.06 20:36 
Hi,

ich habe in der DF schon gesucht, aber nichts richtiges gefunden.
Ich möchte, wenn mein Programm einen Fehler macht, (fast immer(naja immer)) dann soll in einer StatusBar "Fehler" angezeigt werden, bis das Fenster geschlossen ist.

Geht das???

Gruss,

Mindforce

_________________
Our force; in mind.
popi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Sa 10.06.06 20:57 
Hmmm, ich bin auch Anfänger...

Aber mit try...except kann man Fehler abfangen...

Hoffe, das ist das was Du suchst...

Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Was auch immer;
begin

try
//... das was Du tun möchtest
except
//...das was passieren soll, wenn der Fall eintrifft, dass das was Du wolltest nicht eintrifft  :wink: 
end;


end;

Gruß

popi

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Sa 10.06.06 21:03 
Hi,

danke für deine Antwort.
Aber was meinst du mit

ausblenden Delphi-Quelltext
1:
2:
try
//... das was Du tun möchtest


Gruss,

Mindforce

_________________
Our force; in mind.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 10.06.06 21:11 
Zitat:
Ich möchte, wenn mein Programm einen Fehler macht
Immer diesen Programme, die obwohl daer Code erste Sahne ist trotzdem Fehler machen ;-)
Zitat:
Was du tumn möchtest
ist der Codeabschnitt bei dem eine Exception geworfen werden könnte.

_________________
Markus Kinzler.
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Sa 10.06.06 21:23 
Hi,

dh.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure Machwas;

...

procedure Machwas
begin

try
//Nix

execpt
statusbar.dings.undweiter:='Fehler gefunden';


Ne oder??
Und ausserdem weiss ich garnicht wie oder was ich deklarieren soll... :zwinker:

Gruss,

Mindforce

_________________
Our force; in mind.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 10.06.06 21:31 
Bei der Fehlerbehandlung gibt es 2 Möglichkeiten, Fehlervermeidung (bessere Methode) und das Abfangen von Fehlern.

Manche Fehler kann man vermeiden andere nicht.

Bsp. Vermeidung möglich: Division zweier Zahlen -> Divisor könnte 0 sein
ausblenden Delphi-Quelltext
1:
if divisor <> 0 then erg := zahl / divisor else //Fehlerausgabe.					


oder Abfangen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
try
  erg := zahl / divisor;
except
  on EDivByZeoro do //Fehlerausgabe
end;


Andere Fehler, wie z.B. beim Versuch eine Datei zu Öffnen, kann man aber nicht vermeiden.

_________________
Markus Kinzler.
mtin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Sa 10.06.06 21:35 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Label1.Caption:='ok';
try
IntToStr(5.5)
except Label1.Caption:='fehler';

nach diesem Code wird das Label1 "fehler" lauten

ausblenden Delphi-Quelltext
1:
2:
3:
4:
Label1.Caption:='ok';
try
IntToStr(5)
except Label1.Caption:='fehler';

nach diesem Code wird das Label1 "ok" lauten
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Sa 10.06.06 21:51 
Hi

kann mir jemand dafür mal die Unit geben, NICHT weil ich zu faul bin, ...
Wäre ich euch SEHR dankbar für!!! :zwinker:

Gruss,

Mindforce

_________________
Our force; in mind.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 10.06.06 21:53 
Welche Unit?

_________________
Markus Kinzler.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 10.06.06 22:05 
man bemerke, zum try..except gehört noch ein end zwingend dazu, sonst gibts Fehlermeldungen.
Sprich:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
try
...
except
...
end;


Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
Luke1410
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 31



BeitragVerfasst: Sa 10.06.06 22:07 
Wo liegt denn noch dein Problem? mkinzler hat dir doch eigentl schon alles geschrieben, wie's funktioniert.
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Sa 10.06.06 22:10 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
unit Unit1;


interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FileCtrl, StdCtrls, Buttons, Mask, ExtDlgs, ComCtrls;

type
  TForm1 = class(TForm)
    FileListBox1: TFileListBox;
    Button1: TButton;
    Button2: TButton;
    ListBox1: TListBox;
    Label1: TLabel;
//Und so weiter NE???


So ungefähr... :zwinker:

Gruss,

Mindforce

_________________
Our force; in mind.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 10.06.06 22:23 
hä?

try..except verwendest du doch in den Prozeduren um einzelne Zeilen zu kapseln....

_________________
Programmers never die, they just GOSUB without RETURN
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Sa 10.06.06 22:35 
Wo soll ich dat denn hineindeklariren

In einem Button schonmal nicht...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Procedure Machwas;

Procedure Tform1.Machwas;
begin

try

exept

end;
end;...


geht ja nicht.

Gruss,

Mindforce

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt

_________________
Our force; in mind.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 10.06.06 22:48 
Klar geht das:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
Procedure sonstwas;
begin
try
  (Form1.Components[43] as TButton).Caption := 'Ich lebe'; //diese Zeile wird äußerst wahrscheinlich eine Exception hervorrufen
except
  showmessage('Der Fehler ist also doch aufgetreten');
end;
end;


Auf
Wunsch kannst du noch nach Exception-Klassen unterscheiden, das geht dann so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Procedure sonstwas;
begin
try
  (Form1.Components[43] as TButton).Caption := 'Ich lebe'; //diese Zeile wird äußerst wahrscheinlich eine Exception hervorrufen
except
  on E: EAccessViolation do begin
    showmessage('Der Text der Excpetion lautet: ' + E.Message);
  end;
end;
end;


Verstanden?

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
proprogrammierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 43


Delphi 5, Delphi 2005
BeitragVerfasst: Sa 10.06.06 22:52 
ich würd mir erstmal an deiner stelle überlegen, wo fehler auftreten könnten. so, und dann musst du an diesen stellen in deinem code die try except blöcke 'einfügen' :

Beispiel:

Du überlegst dir : hm, Click auf Button1 könnte Probleme machen, also -

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  anz:= 0;
  try Rechne except on exception do                                             //fängt hier Division durch 0 ab
    application.messagebox('Fehler aufgetreten.','Fehler',MB_OK+MB_ICONERROR) 
  end;
end;

function TForm1.Rechne : real;
begin
  result:= 5 / anz;
end;


bigup