Recent

Author Topic: [SOLVED] On error ShowMessage repeats twice  (Read 1933 times)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
[SOLVED] On error ShowMessage repeats twice
« on: October 12, 2019, 11:20:05 am »
Code: [Select]
 
AssignFile(fileText, selectedDir + PathDelim + 'chipdata.def');

  Try
     Reset(fileText);
  except
     on E: Exception do
        begin
           ShowMessage('Opening ' + selectedDir + PathDelim + 'chipdata.def'
               + LineEnding + 'Failed with error: ' + E.Message + LineEnding);
           Form1_Main.Close;
        end;
  end;
 

If the file is not found, then the ShowMessage executes twice before the program closes.

The same behaviour is observed on Windows and macOS.

Got me  :o
« Last Edit: October 16, 2019, 09:48:31 am by trev »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: On error ShowMessage repeats twice
« Reply #1 on: October 12, 2019, 11:37:38 am »
Code: Pascal  [Select][+][-]
  1.    
  2.     AssignFile(fileText, selectedDir + PathDelim + 'chipdata.def');
  3.     try
  4.       Reset(fileText);
  5.     except
  6.       on E: EInOutError do
  7.         begin
  8.           ShowMessage('Opening ' + selectedDir + PathDelim + 'chipdata.def'
  9.               + LineEnding + 'Failed with error: ' + E.Message + LineEnding);
  10.           Form1_Main.Close;
  11.         end;
  12.     end;
       

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: [SOLVED] On error ShowMessage repeats twice
« Reply #2 on: October 16, 2019, 09:50:39 am »
The solution (or maybe workaround) was to check if the file exists first. Then the subsequent on error message shows up only once and the application exits as expected. Not really any the wiser, but it works :)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: [SOLVED] On error ShowMessage repeats twice
« Reply #3 on: October 16, 2019, 11:30:20 am »
New features, new errors.

Do it the old way:

Code: Pascal  [Select][+][-]
  1. var io : integer;
  2. ....
  3. {$I-}
  4. AssignFile(fileText, selectedDir + PathDelim + 'chipdata.def');    
  5. Reset(fileText);
  6. {$I+}
  7. io := ioresult;
  8. if io <> 0 then  
  9.         begin
  10.           ShowMessage('Opening ' + selectedDir + PathDelim + 'chipdata.def'
  11.               + LineEnding + 'Failed with IOerror: ' + IntToStr(io) );
  12.           Form1_Main.Close;
  13.         end;
   
Winni

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: On error ShowMessage repeats twice
« Reply #4 on: October 17, 2019, 07:42:24 am »
Code: Pascal  [Select][+][-]
  1.    
  2.        on E: EInOutError do
  3.  
     

This change made no difference. The error message appeared twice before the form closed.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: [SOLVED] On error ShowMessage repeats twice
« Reply #5 on: October 17, 2019, 08:21:11 am »
New features, new errors.

Do it the old way:

Again, no difference. Two identical messages before form closes.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: [SOLVED] On error ShowMessage repeats twice
« Reply #6 on: October 17, 2019, 08:59:17 am »
Can you give a simple compilable example that demonstrates the issue?

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: [SOLVED] On error ShowMessage repeats twice
« Reply #7 on: October 18, 2019, 12:00:03 am »
I shall endeavour to do so after I finish my current application update; maybe in a week or so. Thanks for the interest.

 

TinyPortal © 2005-2018