Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-09

UTF8Tools problem

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vojtěch Čihák
Hi,
 
I have this code for improved autocomplete of TCombo:
 
var i, aCharMatch, aIndex: Integer;
    aCmbText, aItemStr: TUTF8Scanner;
    aStr: string;
begin
  with TStringGrid(TComboBox(Sender).Parent) do
    if TComboBox(Sender).ItemIndex>=0
      then Cells[Col, Row]:=TComboBox(Sender).Items[TComboBox(Sender).ItemIndex]  { item matched by Combo }
      else 
      begin  { try match item by UTF8Scanner }
        if TComboBox(Sender).Items.Count>0 then
          begin
            aIndex:=0; 
            aStr:=UTF8lowercase(trim(TComboBox(Sender).Text));
            if aStr'' then
              begin
                aCmbText:=TUTF8Scanner.Create(aStr);
                aItemStr:=TUTF8Scanner.Create;   
                aCharMatch:=1;
                for i:=0 to TComboBox(Sender).Items.Count-1 do
                  begin
                    aItemStr.UTF8String:=UTF8lowercase(TComboBox(Sender).Items[i]);
                    while (not aCmbText.Done) and (not aItemStr.Done) do
                      begin
                        if aCmbText.Next=aItemStr.Next then
                          if aCmbText.CharPos>aCharMatch then
                            begin
                              inc(aCharMatch);
                              aIndex:=i;
                            end;
                      end;
                    aCmbText.Reset;
                  end; 
                aCmbText.Free;
                aItemStr.Free;   
              end;
            TComboBox(Sender).ItemIndex:=aIndex;
            Cells[Col, Row]:=TComboBox(Sender).Items[aIndex];
          end;
      end;               
 
It uses UTF8tools http://wiki.lazarus.freepascal.org/UTF8_Tools by Theo.
I tried to compile project after while (few month) and I have got this error message:
 
unicodeinfo.pas(1180,53) Error: Wrong number of parameters specified for call to "UnicodeToUtf8"
Error: Found declaration: UnicodeToUtf8(PChar;PUnicodeChar;Int64):Int64;
 
Question is: How can I repair unicodeinfo.pas? Or better, can I do the same job without UTF8Tools package?
 
Thanks for help,
 
V.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170930/7a3046f8/attachment.html>

Reply by email

Juha Manninen
to Vojtěch Čihák
Vojtěch Čihák wrote
unicodeinfo.pas(1180,53) Error: Wrong number of parameters specified for call to "UnicodeToUtf8" Error: Found declaration: UnicodeToUtf8(PChar;PUnicodeChar;Int64):Int64;

I downloaded UTF8tools from the wiki page and compiled it without problems. I don't see UnicodeToUtf8 with 3 parameters anywhere. LazUTF8 has 2 versions: function UnicodeToUTF8(CodePoint: cardinal): string; // UTF32 to UTF8 function UnicodeToUTF8(CodePoint: cardinal; Buf: PChar): integer; // UTF32 to UTF8

Question is: How can I repair unicodeinfo.pas?

unicodeinfo.pas looks OK. You have another version of UnicodeToUtf8() coming from somewhere.

Or better, can I do the same job without UTF8Tools package?

Unit LazUnicode has iterators for both codepoints and Unicode "characters".

Juha

Reply by email

Vojtěch Čihák
to Vojtěch Čihák:   I have this code for improved autocomplete of TCombo:   var i, aCharMatch, aIndex:…

Thanks, I had old version of UTF8Tools which didn't have LazUTF8 in "uses" so it poited to FPC's:  
function UnicodeToUtf8(Dest: PChar; Source: PUnicodeChar; MaxBytes: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif} function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PUnicodeChar; SourceChars: SizeUInt): SizeUInt;   
Now it works.
 
I'll look on the solution via LazUnicode too, it would reduce one dependency on external package.  
V.
 
 

Reply by email