<p dir="ltr">Hi Tomas,</p>
<p dir="ltr">TEventobject.create is the only thing called in the thread constructor, and teventobject.create is indeed calling a API function in order to create the event.  There is no other way to find out if teventobject.create failed as teventobject.handle always has a value even if it fails. <br>
So what I am getting at is its extremely likely getlasterror applies even though it does not call  winapi directly.</p>
<p dir="ltr">Since I solved it by giving the name param a giud, the next thing to ask is why does teventobject fail kind of silently when the name parm is blank over time?</p>
<p dir="ltr">Also keep in mind this is third party code, so I don't really know why they used teventobject as much as they did, I would imagine they didn't want to use critical sections all over the place.<br></p>
<p dir="ltr">And yes the event object does get destroyed when the thread finishes.<br>
I understand what your saying about the differences between getlasterror and getlastoserror.</p>
<p dir="ltr">I do appreciate the comments :-)</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Oct 14, 2016 12:28 PM, "Tomas Hajny" <<a href="mailto:XHajT03@hajny.biz">XHajT03@hajny.biz</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, October 14, 2016 17:44, Snorkl e wrote:<br>
<br>
<br>
Hi,<br>
<br>
> Hi, actually getlasterror only applies to the calling thread,<br>
> getlastOSerror is the one not to use.<br>
> Anyway I think I found the solution.<br>
 .<br>
 .<br>
<br>
I'm glad that you found potential reason of the problem, but your<br>
assumption regarding GetLastError and GetLastOSError is not entirely<br>
correct. You're right that GetLastError returns the last error in the<br>
current thread, because that is written in the respective MSDN<br>
documentation. I don't think that this is in contradiction to the<br>
information from Jonas though.<br>
<br>
Moreover, the only difference between GetLastError and GetLastOSError is<br>
the fact that GetLastError is direct part of the MS Windows API (and thus<br>
it behaves exactly as described in MSDN, but it is platform-specific),<br>
whereas GetLastOSError is the FPC RTL abstraction for returning error<br>
information from the underlying operating system (available across<br>
different platforms). As such, you should rely on the behaviour of<br>
GetLastOSError only to the level documented in the FPC documentation (in<br>
other words, certain aspects described in MSDN documentation for<br>
GetLastError may not be valid for GetLastOSError on all FPC supported<br>
platforms due to differences in error handling on different platforms).<br>
<br>
As an example, direct calls to Windows API bypassing FPC RTL and resulting<br>
in an error would change the value returned by GetLastOSError on MS<br>
Windows, whereas direct calls to OS/2 API bypassing FPC RTL and resulting<br>
in an error would _not_ change the value returned by GetLastOSError on<br>
OS/2.<br>
<br>
The implementation of GetLastOSError for MS Windows (Win32 or Win64)<br>
consists of a direct call to GetLastError and thus the same caveats apply<br>
for them on that platform.<br>
<br>
Tomas<br>
<br>
<br>
><br>
> On Oct 14, 2016 9:23 AM, "Jonas Maebe" <<a href="mailto:jonas.maebe@elis.ugent.be">jonas.maebe@elis.ugent.be</a>> wrote:<br>
><br>
>> On 14/10/16 02:43, Snorkl e wrote:<br>
>><br>
>>> Anyway, I am using a third party SFTP server lib and it creates a<br>
>>> thread<br>
>>> inherited from tthread and in the create event of the tthread<br>
>>> descendant<br>
>>> it does this:<br>
>>> (It uses this thread to read and write data on the socket)<br>
>>><br>
>>> FDataAvailable := TEvent.Create(nil, True, False, '');  //tevent maps<br>
>>> to<br>
>>> teventobject<br>
>>><br>
>>> {$IFDEF MSWINDOWS}<br>
>>>   lasterr:=GetLastError;<br>
>>><br>
>><br>
>> GetLastError() will return the error code of the last Windows API call<br>
>> that has been performed. I doubt TEvent.Create() guarantees not to call<br>
>> any<br>
>> Windows API's between creating an event using a Windows event and<br>
>> returning. E.g., it might allocate or free memory in between, or the FPC<br>
>> RTL may have done that in the context of handling the constructor call.<br>
>><br>
>> You should only call GetLastError() immediately after calling a Windows<br>
>> API function yourself. In any other case, you cannot know what may have<br>
>> transpired in between.<br>
>><br>
>><br>
>> Jonas<br>
<br>
<br>
______________________________<wbr>_________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.<wbr>org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">http://lists.freepascal.org/<wbr>cgi-bin/mailman/listinfo/fpc-<wbr>pascal</a><br>
</blockquote></div></div>