<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 31 Oct 2012, at 13:29, Giuliano Colla wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; ">In Linux environment the following code:<br><br> try<br> USBOut := FileOpen(UsbDev,fmOpenWrite);<br> except<br> result := True;<br> end;<br><br>is used in a Lazarus application to get a handle to write to an USB device, and did work fine in fpc 2.4.<br><br>I migrated the application to Lazarus 1.0 wich uses fpc 2.6, and it stopped working. FileOpen returns -1, without rising an exception, which made me struggle to find out what was happening.<br></span></span></blockquote><div><br></div><div>FPC 2.6 added support for file locking on Unix platforms. You probably should use </div><div><br></div><div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; "> USBOut := FileOpen(UsbDev,fmOpenWrite or fmShareDenyNone);</span></span><br></div><div><br></div><div>Otherwise FileOpen will try to get an exclusive (write) lock on that device, which may well not be possible.</div><div><br></div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; ">Moreover I don't understand why the call returns a -1, meaning that the Open failed, without rising an exception.<br></span></span></blockquote></div><br><div>Does FileOpen raise an exception in Delphi when locking fails?</div><div><br></div><div><br></div><div>Jonas</div></body></html>