Recent

Author Topic: Identifier not found "SysToUtf8"  (Read 340 times)

lgrfbs

  • New Member
  • *
  • Posts: 42
    • My CV page (On Swedish only)
Identifier not found "SysToUtf8"
« on: February 26, 2020, 04:10:43 pm »
I hope I posting in the right part of this forum.
I opened an older Lazarus project today that has lived on another computer before and now I got the following error message:
unit1.pas(3177,21) Error: Identifier not found "SysToUtf8"

Please take it step by step.
I'm a little rusty about Pascal/Lazarus when I haven't touched it for a while now, how do I solve this problem?

Setup:
Windows10 Home Build 18362
Lazarus 1.8.4 r57972 FPC 3.0.4 i386-win32-win32/win64
OS : Win 10 64bit Home * Win 7 64bit Professional
Lazarus 1.8.4 r57972 FPC 3.0.4 i386-win32-win32/win64
Delphi 7.0 (Build 4.453)

Handoko

  • Hero Member
  • *****
  • Posts: 3439
  • My goal: build my own game engine using Lazarus
Re: Identifier not found "SysToUtf8"
« Reply #1 on: February 26, 2020, 04:14:07 pm »
Try to add "LazUTF8" in the uses clause.

More info:
https://wiki.freepascal.org/Lazarus_with_FPC3.0_without_UTF-8_mode
« Last Edit: February 26, 2020, 04:22:59 pm by Handoko »

howardpc

  • Hero Member
  • *****
  • Posts: 3359
Re: Identifier not found "SysToUtf8"
« Reply #2 on: February 26, 2020, 04:21:33 pm »
Try adding LazUtils to the uses clause of the unit that gives the error.

lgrfbs

  • New Member
  • *
  • Posts: 42
    • My CV page (On Swedish only)
Re: Identifier not found "SysToUtf8"
« Reply #3 on: February 26, 2020, 04:26:43 pm »
howardpcWere can I find LazUtils and install it?
OS : Win 10 64bit Home * Win 7 64bit Professional
Lazarus 1.8.4 r57972 FPC 3.0.4 i386-win32-win32/win64
Delphi 7.0 (Build 4.453)

lgrfbs

  • New Member
  • *
  • Posts: 42
    • My CV page (On Swedish only)
Re: Identifier not found "SysToUtf8"
« Reply #4 on: February 26, 2020, 04:32:01 pm »
The project is a Windows program, if this is helping.
OS : Win 10 64bit Home * Win 7 64bit Professional
Lazarus 1.8.4 r57972 FPC 3.0.4 i386-win32-win32/win64
Delphi 7.0 (Build 4.453)

howardpc

  • Hero Member
  • *****
  • Posts: 3359
Re: Identifier not found "SysToUtf8"
« Reply #5 on: February 26, 2020, 05:15:57 pm »
I see you are using 1.8.2. I have no idea why you choose not to use the latest release version. So you need to do as handoko writes and add LazUTF8 to your uses clause.

lgrfbs

  • New Member
  • *
  • Posts: 42
    • My CV page (On Swedish only)
Re: Identifier not found "SysToUtf8"
« Reply #6 on: February 26, 2020, 05:19:52 pm »
The only reason is that I've been from Lazarus for a while, so an upgrade might solve this?
OS : Win 10 64bit Home * Win 7 64bit Professional
Lazarus 1.8.4 r57972 FPC 3.0.4 i386-win32-win32/win64
Delphi 7.0 (Build 4.453)

Bart

  • Hero Member
  • *****
  • Posts: 3727
    • Bart en Mariska's Webstek
Re: Identifier not found "SysToUtf8"
« Reply #7 on: February 26, 2020, 05:29:56 pm »
SysToUtf8() does nothing (unless you build with DisableUTF8RTL defined).

If you need to convert a Windows copepage encoded string (e.g if you read an ANSI encoded file) then you need WinCPToUTF8().
Utf8ToWinCP() obviously does the reverse.

Both functions are in the LazUtf8 unit.

Bart

lgrfbs

  • New Member
  • *
  • Posts: 42
    • My CV page (On Swedish only)
Re: Identifier not found "SysToUtf8"
« Reply #8 on: February 26, 2020, 06:25:31 pm »
I did a upgrade to:
Lazarus 2.0.6 r62129 FPC 3.0.4 x86_64-win64-win32/win64

SysToUtf8 is in the routine to read a setting file that the user should be able to change in, but the program should not require a specific character set. Just because the user has accidentally saved in "wrong" character set and that's why SysToUtf8 command is there for the input data in the application to be correct.


So Bart, should I replace all SysToUtf8 to WinCPToUTF8 then?
OS : Win 10 64bit Home * Win 7 64bit Professional
Lazarus 1.8.4 r57972 FPC 3.0.4 i386-win32-win32/win64
Delphi 7.0 (Build 4.453)

Bart

  • Hero Member
  • *****
  • Posts: 3727
    • Bart en Mariska's Webstek
Re: Identifier not found "SysToUtf8"
« Reply #9 on: February 26, 2020, 10:04:39 pm »
If your setting file is in ANSI encoding (the default encoding for text files on Windows, e.g. if you create them with Notepad), then you need to convert then to UTF8 (since String is UTF8 in LCL/Lazarus).

If you created the file using a Lazarus program, then the encoding of the strings actually will be UTF8.

Notice that all of this only matters if the setting file contains any characters that are not lower ASCII.

You can simply test this by loading the file into a TMemo and see if it looks OK.
If you see odd characters, or questionmarks that do not belong there, most likely the file is ANSI encoded.
If it looks OK, then either the file is UTF8, or it is pure ASCII (since all ASCII is by definition alss correct UTF8).

Bart