× CodeTyphon MS Windows (XP, Vista, Win7, Win8.x and Win10) OS Development, discussions and problems

Question UTF-8 localize error

  • Felix Sanchez
  • Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 6 months ago #2205 by Felix Sanchez
UTF-8 localize error was created by Felix Sanchez
Anyone know why when I are in the Ide and make a text in a edit book or other LCL like calendar and use special characters (spanish, áéíóú or ñ) I can't not see only wrong character
I use windows 7 and appear the fpc have a bug form information I can found in google
but how can fix?

Please Log in or Create an account to join the conversation.

More
9 years 5 months ago - 9 years 5 months ago #2450 by frtrnr
Replied by frtrnr on topic UTF-8 localize error
"áéíóú " are displayed correctly in my laz code editor. (win7 x64 Chinese)
so I think if your OS lacks a font, e.g. simsun.ttf?

///////////////////////////////////////////////
Sorry, maybe I have mistaken your meaning!
Last edit: 9 years 5 months ago by frtrnr.

Please Log in or Create an account to join the conversation.

  • avra
  • Visitor
  • Visitor
9 years 5 months ago #2452 by avra
Replied by avra on topic UTF-8 localize error
If you can type these characters in Notepad, then change font in IDE source editor.

Please Log in or Create an account to join the conversation.

  • 4aiman
  • 4aiman's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Comix creator
More
9 years 4 months ago - 9 years 4 months ago #2455 by 4aiman
Replied by 4aiman on topic UTF-8 localize error
I decided to post it here rarther then starting new thread:
I have some cross-platform app that works with files and there're smth strange about codepages under win (xp)
Here's an example:
if SPD.Execute then [color=#4400ff]//don't ask why, but SPD is of TSaveFileDialog class[/color]
           begin
                [color=#ff0000]path:=Utf8ToSys(ExtractFilePath(SPD.FileName));
                nam:=UTF8ToSys(ExtractFileNameOnly(SPD.FileName));[/color] [color=#4400ff]//here I change IDE's utf8 into system cp, right? Right?[/color]
                s:=TMemoryStream.Create;
                s.Write(Length(icons.icons),sizeof(integer));
                i:=1; s.Write(i,sizeof(byte));
                for i:= 0 to length(icons.icons) - 1 do
                    begin
                         s.WriteAnsiString(icons.icons[i].name);
                         ForceDirectories(path+nam);
                           //now ^ THIS works fine with russian letters and I have my folder created :) 

                         icons.icons[i].graphic.SaveToFile(path+nam+PathDelim+'pix_'+inttostr(i)+'.png');
                           // ^ but this line produces exception! 
                           // My program can't create file "??????? ????". 
                           // Yep, instead this "?" there should be russian characters. 
                           // Oh, icons.icons[i].graphic is of TPortableNetworkGraphic 
                           // class...[/color]
                    end;
             s.SaveToFile(ChangeFileExt(spd.FileName,'.sat'));
             s.Free;
             exit;
        end;

Strangely, there's NO difference whether I use {H+} or not - forcedirectories always works and savetofile not :(

Forcedirectories: If {H+} is ON then I get my folder in ANSI (yep, like I should) and if there's no {H+} then I get this: db.tt/UgTYFsf5 (yep, like I should, 2)


Savetofile: There's always error while creating a file.

Could anyone suggest anything to save a png file under win with non-latin character in the path?

コンソールマニアック
Last edit: 9 years 4 months ago by 4aiman.

Please Log in or Create an account to join the conversation.

  • 4aiman
  • 4aiman's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Comix creator
More
9 years 4 months ago #2484 by 4aiman
Replied by 4aiman on topic UTF-8 localize error
UP ^
...
sorry for that...

コンソールマニアック

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
9 years 4 months ago #2485 by Sternas Stefanos
Replied by Sternas Stefanos on topic UTF-8 localize error
Try this procedure

function ChangeFileExt2(const aFileName, aExtension: string): string;
  var
    c1,c2:integer;
    ss1:string;
 begin
    result:='';
    ss1:='';
    if aFileName='' then exit;

    c1:=Length(aFileName);
    c2:=Length(aExtension);

    if c2<1 then
     begin
         result:=aFileName+'.'+aExtension;
     end else
     begin
         ss1:=LeftStr(aFileName,c1-c2-1);
         result:=ss1+'.'+aExtension;
     end;
 end;

PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

More
9 years 4 months ago - 9 years 4 months ago #2500 by Rain
Replied by Rain on topic UTF-8 localize error
If saving an UTF8 filename does not work (as in case of TStringlist.SaveToFile() )
use a temp flename first, then rename, using
RenameFileUTF8(tempname, utf8name) 
from FileUtil (by adding package LazUtils)

program testutf8;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes  ,
  { you can add units after this }
   SysUtils , FileUtil
  ;
var
  utf8name, tempansiname :string;
  testlist: TStringlist;
begin
   testlist := TStringList.create();
   testlist.Append('That is 0x03E2 = Ϣ');
   utf8name := 'ϢϢϢ.txt'  ;
   //testlist.SaveToFile(UTF8ToSys(utf8name)); // unable to create file ???.txt
   //testlist.SaveToFile(SysToUTF8(utf8name)); // creates wrong filename: ϢϢϢ.txt
   //testlist.SaveToFile(utf8name);            // creates wrong filename: ϢϢϢ.txt
   tempansiname := 'temp8899.tmp';
   testlist.SaveToFile(tempansiname);          // creates temp filename: temp8899.tmp
   RenameFileUTF8(tempansiname, utf8name);     // creates correct filename: ϢϢϢ.txt
end.
                
Last edit: 9 years 4 months ago by Rain.

Please Log in or Create an account to join the conversation.

  • 4aiman
  • 4aiman's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Comix creator
More
9 years 4 months ago - 9 years 4 months ago #2511 by 4aiman
Replied by 4aiman on topic UTF-8 localize error
Sternas, Rain - thanks to both of you, and my apologies for delay.

Once I dug it up, all of that "UTF business" seems pretty obvious to me, but just in case some other people might need this, "the path I've walked through" is here, under spoiler:
Warning: Spoiler!

So, my code should be as folows:
Warning: Spoiler!

コンソールマニアック
Last edit: 9 years 4 months ago by 4aiman.

Please Log in or Create an account to join the conversation.