Solved

How can I get error number from exception

Posted on 1998-08-10
4
365 Views
Last Modified: 2010-04-04
Earler with pascal the error code number was geven by IOResult function.
But in delphi with exception handling how can I get the last error number for example I/O errors code.
0
Comment
Question by:Motaz
  • 2
4 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1361828
If I'm getting you right here is an example..otherwise give some more details please....thanx

var

  F: file of Byte;
begin
  if OpenDialog1.Execute then begin
    AssignFile(F, OpenDialog1.FileName);
    {$I-}
    Reset(F);
    {$I+}
    if IOResult = 0 then
      MessageDlg('File size in bytes: ' + IntToStr(FileSize(F)),
        mtInformation, [mbOk], 0);
    else
      MessageDlg('File access error', mtWarning, [mbOk], 0);
  end;
end;

Regards,
Viktor Ivanov
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 10 total points
ID: 1361829
Hi Motaz,

 if you use exceptions for your IO control then the exceptions you get are of type EInOutError :

type
 EInOutError = class(Exception)
   ErrorCode: Integer;
 end;

So the ErrorCode give the same result as IOResult in early pascal days (or still in delphi for compatibility?)

try
 ...
except
 on E: Exception do showMessage('ErrorCode: ', E.ErrorCode);
end;

Zif.
0
 
LVL 7

Author Comment

by:Motaz
ID: 1361830
Thanks ZifNab, you are a porfull Delphi programmer. I hope I become like you. I search for this error number for a long time. Thanks again for your help. But there is some bugs in your code but it isn't important, that is the correction :

procedure TForm1.Button1Click(Sender: TObject);
var
     f:file;
begin
  try
    AssignFile(f,'NonExist.err');
    Reset(f);
    closefile(f);
  except
  on E: EinoutError do
    showMessage('ErrorCode: '+IntToStr(E.ErrorCode));
  end; (*** end try ***)

end;

Motaz.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361831
Motaz, ok correct, there is a bug! Thanks for letting me know. I did it by hand, so there was a possibility for a bug. Zif.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: ForceDirectory plain function 7 50
Delphi, TImage, Png 2 32
Delphi Firemonkey send email on Android 1 46
how can i delete one control based on its tagstring ? 6 39
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question