Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
Access Denied
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
« previous
next »
Print
Pages: [
1
]
Author
Topic: Access Denied (Read 1723 times)
user5
Sr. Member
Posts: 419
Access Denied
«
on:
June 23, 2019, 01:33:21 pm »
Is the code below an acceptable way to use a try statement with OpenDialog?
I'm trying to provide protection against an Access Denied error. Thanks.
Code: Pascal
[Select]
[+]
[-]
try
try
begin
if
opendialog1
.
Execute
=
true
then
begin
filename
:
=
opendialog1
.
FileName
;
end
end
;
except
On E
:
Exception
do
begin
sound
(
350
)
;
newerror
:
=
true
;
end
;
end
;
finally
;
end
;
Logged
Thaddy
Hero Member
Posts: 19632
Glad to be alive.
Re: Access Denied
«
Reply #1 on:
June 23, 2019, 01:41:55 pm »
empty finally sections are never acceptable. (Same goes for empty except statements)
I also miss a specialized exception EAccessDenied and a re-raise if it is something else......
Bad programming, sorry.
«
Last Edit: June 23, 2019, 01:45:31 pm by Thaddy
»
Logged
Any "programmer" that knows only one programming language is not a programmer
user5
Sr. Member
Posts: 419
Re: Access Denied
«
Reply #2 on:
June 23, 2019, 02:28:13 pm »
Thank you for your response. Could you give me a brief example of something that is better?
Logged
ASerge
Hero Member
Posts: 2514
Re: Access Denied
«
Reply #3 on:
June 24, 2019, 03:11:54 pm »
Quote from: user5 on June 23, 2019, 02:28:13 pm
Thank you for your response. Could you give me a brief example of something that is better?
In Windows, "OpenDialog" handles access denied errors before closing, so the code:
Code: Pascal
[Select]
[+]
[-]
OpenDialog1
.
Execute
;
Until you tell us more, it's better than your code.
Logged
Thaddy
Hero Member
Posts: 19632
Glad to be alive.
Re: Access Denied
«
Reply #4 on:
June 24, 2019, 03:17:25 pm »
Indeed It would help a great deal.
Logged
Any "programmer" that knows only one programming language is not a programmer
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
Access Denied
TinyPortal
© 2005-2018