[fpc-pascal] teventobject.create fails with error 161
Jonas Maebe
jonas.maebe at elis.ugent.be
Fri Oct 14 16:23:20 CEST 2016
On 14/10/16 02:43, Snorkl e wrote:
> Anyway, I am using a third party SFTP server lib and it creates a thread
> inherited from tthread and in the create event of the tthread descendant
> it does this:
> (It uses this thread to read and write data on the socket)
>
> FDataAvailable := TEvent.Create(nil, True, False, ''); //tevent maps to
> teventobject
>
> {$IFDEF MSWINDOWS}
> lasterr:=GetLastError;
GetLastError() will return the error code of the last Windows API call
that has been performed. I doubt TEvent.Create() guarantees not to call
any Windows API's between creating an event using a Windows event and
returning. E.g., it might allocate or free memory in between, or the FPC
RTL may have done that in the context of handling the constructor call.
You should only call GetLastError() immediately after calling a Windows
API function yourself. In any other case, you cannot know what may have
transpired in between.
Jonas
More information about the fpc-pascal
mailing list