Recent

Author Topic: Bug SysUtils.FindClose in Windows ?  (Read 2391 times)

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Bug SysUtils.FindClose in Windows ?
« on: May 24, 2018, 08:38:04 am »
Hi,
sorry for my bad english.
I'm using fpc 3.0.4.

See this code:
Code: Pascal  [Select][+][-]
  1. procedure TestFindFirst(WrkDir:String);
  2. var PathInfo: TSearchRec;
  3. begin
  4.   SysUtils.FindFirst(AppendPathDelim(WrkDir) + GetAllFilesMask, faDirectory, PathInfo);
  5.   SysUtils.FindClose(PathInfo);
  6.   {$IFDEF MSWINDOWS}
  7.     if (PathInfo.FindHandle <> -1) then begin
  8.   {$ENDIF}
  9.   {$IFDEF Linux}
  10.     if (PathInfo.FindHandle <> nil) then begin
  11.   {$ENDIF}
  12.       ShowMessage('Error !!!');
  13.     end else begin
  14.       ShowMessage('Ok ');
  15.     end;
  16.  
  17.   Halt;
  18. end;
  19.  

On Linux, using TestFindFirst, passing an existing directory, the value of "PathInfo.FindHandle" is nil.
On Windows, using TestFindFirst, passing an existing directory, the value of "PathInfo.FindHandle" that i expecting is -1, but result is the same value that it had before the call of "FindClose".

It's a bug?

Thanks in advance, Mario

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Bug SysUtils.FindClose in Windows ?
« Reply #1 on: May 24, 2018, 08:02:20 pm »
The values of TSearchRec are undefined after FindClose. You should not use any of them afterwards.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: Bug SysUtils.FindClose in Windows ?
« Reply #2 on: May 24, 2018, 08:23:48 pm »
Sorry, I'm just trying to understand the reason for a problem reported here:

https://forum.lazarus.freepascal.org/index.php/topic,41345.msg286830/topicseen.html#new

Sorry, but I thought I canceled this thread.

Hi, Mario

 

TinyPortal © 2005-2018