Recent

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

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 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 »
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

howardpc

  • Hero Member
  • *****
  • Posts: 3178
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

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 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 :)
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

winni

  • Sr. Member
  • ****
  • Posts: 436
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

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 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.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 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.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

howardpc

  • Hero Member
  • *****
  • Posts: 3178
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

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 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.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)