Recent

Author Topic: [SOLVED] Using FindFirst() in Windows 64 with FPC 3.3.1  (Read 1064 times)

AxBen

  • New Member
  • *
  • Posts: 17
[SOLVED] Using FindFirst() in Windows 64 with FPC 3.3.1
« on: February 27, 2024, 07:42:38 pm »
Hi.

I'm trying to use FindFirst() (et al.) in the console. Compiling my source (I'm pretty new to FPC), ppcrossx64 gives me:

>>> Error: Call by var for arg no. 1 has to match exactly: Got "UnicodeString" expected "TRawbyteSearchRec"

The code snippet looks like this:

Code: Pascal  [Select][+][-]
  1. {$Mode DelphiUnicode}
  2. var
  3.    dir: UnicodeString;
  4.    search_rec: TUnicodeSearchRec;
  5. begin
  6.    if FindFirst(dir + '/*', faAnyFile, search_rec) <> -1 then
  7.       ...
  8.  

The docs (3.2.2) state:

Quote
76.15.118 FindFirst
Declaration:
function FindFirst(const Path: UnicodeString; Attr: LongInt; out Rslt: TUnicodeSearchRec) : LongInt
function FindFirst(const Path: RawByteString; Attr: LongInt; out Rslt: TRawbyteSearchRec) : LongIn

so I should normally be good to go.

What am I doing wrong?
« Last Edit: March 01, 2024, 08:53:03 am by AxBen »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Using FindFirst() in Windows 64 with FPC 3.3.1
« Reply #1 on: February 27, 2024, 07:54:07 pm »
Works for me.
fpc 3.3.1-3157-g728be94328 (win32 crosscompiling to win64).

Bart

cdbc

  • Hero Member
  • *****
  • Posts: 1094
    • http://www.cdbc.dk
Re: Using FindFirst() in Windows 64 with FPC 3.3.1
« Reply #2 on: February 27, 2024, 08:07:42 pm »
Hi
you could try this:
Code: Pascal  [Select][+][-]
  1. {$Mode objfpc}{$H+} // objpascal + long strings
  2. var
  3.    dir: String;
  4.    search_rec: TSearchRec;
  5. begin
  6.    if FindFirst(dir + '/*', faAnyFile, search_rec) = 0 then
  7.      // do something
  8.    ...
Don't forget 'FindClose;' when you're done...
It seemed to pick the wrong overload  %)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

TRon

  • Hero Member
  • *****
  • Posts: 2543
Re: Using FindFirst() in Windows 64 with FPC 3.3.1
« Reply #3 on: February 27, 2024, 08:11:44 pm »
From the manual:
Quote
DelphiUnicode
    Delphi compatibility mode. All object-pascal extensions are enabled, and additionally the String keyword refers to a unicode string.
That implies that there is no need to be explicit.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Using FindFirst() in Windows 64 with FPC 3.3.1
« Reply #4 on: February 27, 2024, 08:12:20 pm »
Tested with fpc main as of today (fpc 3.3.1-3996-g6a28ac53da): compiles both in $mode objfpc and $mode delphiunicode, both 32-bit and x-compiled to win64.

Bart

AxBen

  • New Member
  • *
  • Posts: 17
Re: Using FindFirst() in Windows 64 with FPC 3.3.1
« Reply #5 on: February 27, 2024, 08:33:18 pm »
@TRon, cdbc

Quote
That implies that there is no need to be explicit.

This is correct. Replaced UnicodeString with String, but sadly the error remains.

I guess this might be a compiler installation problem on my side. I will probably need to get that straight first (cmp https://forum.lazarus.freepascal.org/index.php/topic,66404.0.html)...

On another note: is there an alternative to FindFirst()? I think Delphi/Lazarus(?) know sth. like System.IoUtils.TDirectory...

TRon

  • Hero Member
  • *****
  • Posts: 2543
Re: Using FindFirst() in Windows 64 with FPC 3.3.1
« Reply #6 on: February 27, 2024, 08:45:44 pm »
I guess this might be a compiler installation problem on my side.
Could be, though the error message itself is strange if it would to be the case. Better get that sorted first  :)


Quote
On another note: is there an alternative to FindFirst()? I think Delphi/Lazarus(?) know sth. like System.IoUtils.TDirectory...
The VCL compatible classes are in the making (you need trunk compiler for that and not everything is implemented (yet))

Lazarus does have a findallfiles function that does the hard work for you but not sure if that is something you had in mind.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2102
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Using FindFirst() in Windows 64 with FPC 3.3.1
« Reply #7 on: February 27, 2024, 09:11:36 pm »
@TRon, cdbc

Quote
That implies that there is no need to be explicit.

This is correct. Replaced UnicodeString with String, but sadly the error remains.

I guess this might be a compiler installation problem on my side. I will probably need to get that straight first (cmp https://forum.lazarus.freepascal.org/index.php/topic,66404.0.html)...

On another note: is there an alternative to FindFirst()? I think Delphi/Lazarus(?) know sth. like System.IoUtils.TDirectory...
Try if your version has unit "FileUtil" or "FileUtils" available, in there are some methods for different things.
I am not aware about FPC highter than stable.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

AxBen

  • New Member
  • *
  • Posts: 17
Re: Using FindFirst() in Windows 64 with FPC 3.3.1
« Reply #8 on: February 28, 2024, 05:10:52 pm »
Meanwhile I managed to compile fpx/ppcrossx64 3.3.1 and now the source compiles w/o. errors.

Thx for your support!

 

TinyPortal © 2005-2018