Solved

suppressing EFOpenErrors in IDE at design time

Posted on 2004-10-14
7
299 Views
Last Modified: 2010-08-05
Hi, I have a wee bit of code loading a stringlist from file

SL.loadfromfile(filename);

that occasionally raises an error. The file is often being read by my prog just as its being created by another PC & in these cases it seems to raise an  EFOpenError.  This is fine & is all handled at runtime, but I want to stop the error breaking execution at design time as I'm actually trying to track down another bug (so I don't want to set a blank application.onexception handler as a solution). I've tried using the {$I-} directive in the offending unit but this doesn't seem to do it. Can anyone help please.

Thanks, P
0
Comment
Question by:Pandora
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 6

Accepted Solution

by:
vadim_ti earned 500 total points
ID: 12314129
tools -> debugger options ->language exceptios

click Add

add EFopenError
place "v" to ignore this exception in debugger


and place code segment generated this exception in block something like it

while true do begin
   try
      LoadFromFile();
      break;      
   except
     sleep(200);
   end
end
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12315343
vadim_ti  has the answer perfectly
0
 
LVL 1

Author Comment

by:Pandora
ID: 12317231
Hi Vadim, thx for your answer -  I did as you said
tools -> debugger options ->language exceptions
added EFOpenError and checked the box to exclude it.

However the program still breaks with an EFOpenError! I'm using delphi 5 on Win xp if that makes a difference

I also already had a try except block on the code, don't know if this makes a difference:

try
   SL.loadfromfile(MOFfilename);
   If IsEncrypted then //ie decrypt contents
      DecryptSLcontents;
   IsDirtyFlag:=false;
   result:=true;
   except
   on E:Exception do
      begin
      result:=false;
      //create a new blank file
      If IsCreateOnError then
         save;
      end;
   end;

Thanks
P

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:vadim_ti
ID: 12317367
what you mean breaks?

make a little test

add button to form, and onbuttonclickevent

procedure TForm1.Button4Click(Sender: TObject);
var
  a:cardinal;
  t:TResStringRec;
begin
  a:=2000;
  t.module := @a;
  t.identifier := 1;
  raise(efopenerror.Create(@t, 'a.a'));
end;

with debugger environment settings like above
programm does not break on this exception (at least in my comp)
if i clear "v" it yes breaks.

may be you have a problem in another segment of a code?
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12318447
He means the code breaks IN DESIGNTIME! The code is part of some component and this component doesn't have an exception handler capturing this error silently when in designmode...

Basically, he needs something like:

try
except
  if not InDesignMode then raise;
end;

to reraise the error while he's in runtime but to keep it quiet in designtime.

There are several different tricks for this but the easiest on is to check if the component state is in design-mode. Thus, he has to alter the component and use:

procedure TYourComponent.YourMethod(YourParameters: YourTypes);
begin
  try
    // Load the file and see it crash and burn.
  except
    if not csDesigning in ComponentState then raise;
  end;
end;

Thus, in designtime it will just shut up... :-)
0
 
LVL 1

Author Comment

by:Pandora
ID: 12318557
Hi Vad,
Tried the test it works as it should so don't know why its being peculiar in the other project. It may be a deeper problem I giuess I'll have to explore more - but I've awarded the pts cos this would normally work it seems.

Alex thx for your comment too - that seems equally helpful as its code specific but I've only just spotted it so I'm sry u missed out on points (& vad got in 1st). But I shall have a play on those lines too. Thx alot & sorry for not spotting it.

best wishes
P
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12319138
No problem, although I do consider Vad's solution pretty dangerous since you might up in an endless loop...

while true do begin
   try
      LoadFromFile();
      break;      
   except
     sleep(200);
   end;
end;

Now, what if the file you're trying to load is permanently unavailable, thus raising an exception every time you load it. It means that you will put your code to sleep permanently, with no way to respond to anything. Maybe a non-endless loop would be better...

  I := 3;
  while (I>0) do
  try
     LoadFromFile();
     I := 0;
   except
     Dec(I);
     if (I = 0) and not (csDesigning in ComponentState) then raise;
   end;

This will try to load the file three times, silently crashing in designtime and loudly crashing in runtime. :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IdTelnet1DataAvailable handler freezes the Application 4 68
Mydac connection data base issue 3 140
Delphi : could not find program, '...exe' 2 149
Reconfigure Delphi Install? 2 47
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now