procedure TForm1.Button1Click(Sender: TObject);
var ws: widestring;
var s: string;
begin
ws := 'test';
s := UTF8Encode(ws);
ShowMessage('CP=' + IntToStr(StringCodePage(s)));
s := s + ' finished';
ShowMessage('CP=' + IntToStr(StringCodePage(s)));
end;
The first value is CP_UTF8=65001, but the second one is back again 1252 (if 1252 is your Windows active code page).
Correction: you also need -dEnableUTF8RTL. Only -FcUTF8 is not enough because FPC will convert the UTF-8 constant to the native encoding of type String which is then Ansi codepage 1252.
This has been the source of complication and confusion all the time in your experiments. You try to use Lazarus with FPC 3.x without using -dEnableUTF8RTL. Sure you can experiment with it but now you make things look very complicated for people who only want to find the simplest way to use Unicode with Lazarus.
The simplest way is -dEnableUTF8RTL!
For example the new user "otoien" is completely confused now (thread "How to use new RTL unicode string support with ANSI (CP1252) file input/output?").
In future please open separate threads for issues with -dEnableUTF8RTL and without it. When experimenting without it, you should mention that it is not a supported nor recommended way!
Using Lazarus with FPC 3.x without -dEnableUTF8RTL is a swamp. You are on your own then.
-dEnableUTF8RTL was created by clever Lazarus developers (mostly Mattias) just to prevent the problems you are facing in your experiments.