Welcome, Guest
Username: Password: Remember me
CodeTyphon MS Windows (Win7, Win8.x, Win10 and Win11) OS Development, discussions and problems
  • Page:
  • 1

TOPIC:

UTF-8 localize error 12 years 4 months ago #2205

  • felixsg
  • felixsg's Avatar Topic Author
  • Visitor
  • Visitor
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.

UTF-8 localize error 12 years 3 months ago #2450

  • frtrnr
  • frtrnr's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 4
  • Thank you received: 0
"áéíóú " 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!

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

Last edit: by frtrnr.

UTF-8 localize error 12 years 3 months ago #2452

  • avra
  • avra's Avatar
  • Visitor
  • Visitor
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.

UTF-8 localize error 12 years 3 months ago #2455

  • 4aiman
  • 4aiman's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Comix creator
  • Posts: 227
  • Thank you received: 12
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?
コンソールマニアック

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

Last edit: by 4aiman.

UTF-8 localize error 12 years 2 months ago #2484

  • 4aiman
  • 4aiman's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Comix creator
  • Posts: 227
  • Thank you received: 12
UP ^
...
sorry for that...
コンソールマニアック

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

UTF-8 localize error 12 years 2 months ago #2485

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
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.

UTF-8 localize error 12 years 2 months ago #2500

  • Rain
  • Rain's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 71
  • Thank you received: 8
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.
                

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

Last edit: by Rain.

UTF-8 localize error 12 years 2 months ago #2511

  • 4aiman
  • 4aiman's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Comix creator
  • Posts: 227
  • Thank you received: 12
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!
コンソールマニアック

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

Last edit: by 4aiman.
  • Page:
  • 1