Autor Beitrag
CyDummy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win XP Pro
D7 Pers
BeitragVerfasst: Do 17.06.04 20:23 
Hallo liebe Kollegen! :wink:

Bei den Fehlermeldungen in meinen Programmen gebe ich immer auch die Zeilennummer mit aus, damit aich bei einer Anfrage besser reagieren kann.
Es ist allerdings sehr lästig, ständig die Nummerierung zu ändern, wenn ich etwas ändere. Gibt es eine Variable o.Ä., die ich stattdessen einfach einsetzen kann und die mir dann die Zeilennummer ausgibt? (in C++ existiert solch eine Variable)

Moderiert von user profile iconTino: Titel geändert.

_________________
LLAP, Cy
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Do 17.06.04 20:29 
Da hab ich mir mal ein kleines Hack ausgedacht (ist aber sehr unschön)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function GetCurrentLine: dword;
asm
 pop  eax
 push eax
 sub  eax, 24
 mov  eax, [eax]
end;

var
 dummy: boolean;
 line: integer;
...
 dummy := true;
 assert(dummy); // <= Die Zeile wird zurückgegeben.
 line := GetCurrentLine;


Nur unter D6 getestet, sollte aber auch mit anderen Laufen
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 17.06.04 20:37 
Wozu brauchst du GetCurrentLine..? Das is doch schon in Assert drinnen:
Delphi Hilfe hat folgendes geschrieben:
Assert takes a Boolean expression and an optional message string as parameters. If the Boolean test fails, Assert raises an EAssertionFailed exception. If a message string was passed to Assert, the exception object is created with that string. Otherwise it is created with a default string indicating that the assertion failed. The message is displayed along with the complete path, filename, and the line number on which Assert failed.

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
CyDummy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win XP Pro
D7 Pers
BeitragVerfasst: Do 17.06.04 20:38 
Danke! :D

Ich werde es gleich morgen in der Uni mal mit D7 testen...

_________________
LLAP, Cy
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Do 17.06.04 20:40 
Und wie willst du daraus die Zeilennummer wieder rausholen ohne gleich einen eigenen Handler dafür zu schreiben? Es muss ja nicht gleich jeder Anwender unbedingt den Namen der Quellcode- Datei wissen (auch wenn ich diese Methode sowieso nicht in einem fertigen Programm anwenden würde)
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 17.06.04 20:44 
obbschtkuche hat folgendes geschrieben:
[..]auch wenn ich diese Methode sowieso nicht in einem fertigen Programm anwenden würde

Eben.. diese Methode ist ja auch hauptsächlich für Debugging-Zwecke gedacht.. und bei einem offizielen Release kann man die Asserts ja per Compiler-Schalter deaktivieren..

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Do 17.06.04 20:55 
Oder eben mit einem eigenen Handler:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure MyAssert(const Message, Filename: string;
    LineNumber: Integer; ErrorAddr: Pointer);
begin
 raise Exception.Create(Message + ' (Zeile ' + inttostr(LineNumber) + ' in Modul ' + MachNettenNamen(FileName) + ')');
end;


ausblenden Delphi-Quelltext
1:
AssertErrorProc := MyAssert;					
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 17.06.04 21:01 
Das is natürlich auch eine Möglichkeit..! ;) Vor allem in Kombination mit OutputDebugString praktisch..!

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
CyDummy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win XP Pro
D7 Pers
BeitragVerfasst: Fr 18.06.04 11:21 
Vielen Dank!
Die Version mit dem eigenen Assert-Handler funktioniert am besten, da die Standardmeldung wirklich nicht zum Releasen zu gebrauchen ist.

_________________
LLAP, Cy
iGoA
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 103

Alle Win´s
D5 Prof
BeitragVerfasst: Fr 18.06.04 11:37 
Kann man so auch einen eigenen Exceptionhandler schreiben?

_________________
"Diner for One" objektorientiert:
"The same method as last year, Ms. Sophie?" (was für´n Schwachsinn)