Autor Beitrag
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Mi 13.04.05 10:43 
Wie kann ich herausfinden, warum z.B. ein SaveToFile fehlgeschlagen ist? Es gibt ja mehrere Gründe, warum das passieren kann, wie z.B. keine Schreibrechte, schreibgeschützte Datei, Datei gerade in Verwendung, ...
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 13.04.05 10:59 
Frag den Wert der Funktion "GetLastError" ab. Liste der Codes gibt's im MSDN und PSDK.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Spaceguide Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Mi 13.04.05 11:33 
Danke, das funktioniert prächtig. Wirkt zwar irgendwie altertümlich, aber funktioniert :)
Spaceguide Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Mi 13.04.05 11:34 
Falls es jemand braucht, hier eine Routine, die die Errorcodes in Strings umwandelt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function SysErrorMessage(ErrorCode: Integer): string;
var
  Len: Integer;
  Buffer: array[0..255] of Char;
begin
  Len := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or
    FORMAT_MESSAGE_ARGUMENT_ARRAY, nil, ErrorCode, 0, Buffer,
    SizeOf(Buffer), nil);
  while (Len > 0) and (Buffer[Len - 1] in [#0..#32, '.']) do Dec(Len);
  SetString(Result, Buffer, Len);
end;
HECHT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24


D7
BeitragVerfasst: Mi 13.04.05 12:35 
Man sollte evt. erwähnen, dass die Funktion SysErrorMessage bereits in SysUtils von Delphi existiert und der Routine von 'Spaceguide' sehr sehr ähnlich sieht.

Ich setzte das untenstehende Pattern schon seit Jahren erfolgreich ein:
ausblenden Delphi-Quelltext
1:
2:
3:
  MessageDlg('Error:' + #13#10 +
             'Systemfehler: ' + IntToStr(GetLastError) + #13#10 +
             SysErrorMessage(GetLastError), mtError, [mbOk], 0);

Gruss
HECHT
Spaceguide Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Mi 13.04.05 13:15 
Da die API-Funktionen bei Delphi doch recht bescheiden dokumentiert sind ist Google oft effizienter ;-)