[Lazarus] How to use strings properly with fixes_1_6 and FPC 3.0.0?

Gabor Boros gaborboros at yahoo.com
Fri Oct 21 13:13:47 CEST 2016


2016. 10. 21. 12:38 keltezéssel, Juha Manninen via Lazarus írta:
>> I do not want to think of where Length, Copy, Delete is good and where UTF8*
>> needed.
>
> Well, you must think when coding. There is no shortcut. :)
>
> BTW, if you are worried about Delphi compatibility there is now unit
> LazUnicode available.

Delphi compatibility not needed for me, but I am a silly coder and don't 
understand why the wiki say you can use Length, Copy, Delete with UTF8. 
See two examples below. First is a Lazarus project with a simple 
editbox, if press á (Alt+160) the form caption show 2. The second 
example is a console project (in Lazarus also), if press á (Alt+160) 
then Enter see 1 as result. Same FCP same Lazarus. Why is there a 
difference in the result?

1.
procedure TForm1.Edit1Change(Sender: TObject);
begin
   Caption:=IntToStr(Length(Edit1.Text));
end;

2.
var
   s:string;

begin
   ReadLn(s);
   Write(Length(s));
   ReadLn;
end.

Gabor


More information about the Lazarus mailing list