• lazarus在linux使用含mask的控件如果mask中包含/或:时在form设计阶段会出现乱码的情况。


    lazarus在linux(树莓派、银河麒麟、Ubuntu 20.04.4 LTS、LMDE 5 Elsie等中文linux)使用含mask的控件如果mask字符串中包含/或:时在form设计阶段会出现乱码,这个Bug还会造成form中的中文保存后再打开时中文全部变为乱码的严重问题。

      运行时:

    由于是设计时的Bug,我不会对IDE debug,不过发现是lcl/MaskEdit.pp的function TCustomMaskEdit.ClearChar(Position : Integer) : TUtf8Char;
    lazarus运行时DefaultFormatSettings.DateSeparator和DefaultFormatSettings.TimeSeparator像没设为初始值,能力有限,暂时直接赋值的方式来解决这Bug.

    function TCustomMaskEdit.ClearChar(Position : Integer) : TUtf8Char;
    var s,s1:TUtf8Char;
    begin
      //For Delphi compatibilty, only literals remain, all others will be blanked
       case GetMask(Position).MaskType Of
        {Char_Space               : Result := #32; //FSpaceChar?; //not Delphi compatible, see notes above}
        Char_HourSeparator        : Result := ':';//DefaultFormatSettings.TimeSeparator;
        Char_DateSeparator        : Result := '/';//DefaultFormatSettings.DateSeparator;
        Char_IsLiteral            : Result := FMask[Position].Literal; //No need to use GetMask, FMask[Position] already has been validated
        otherwise
          Result := FSpaceChar;
      end;
    end;

    还有另一种方法,就在lazarus增加初始值(打开/ide/lazarus.pp,定位88行,在begin下面增加红字4行 )

    {$I revision.inc}
    {$R lazarus.res}
    {$R ../images/laz_images.res}

    begin
      Max_Frame_Dump:=32; // the default 8 is not enough
      {$ifdef linux}
      DefaultFormatSettings.DateSeparator:='-';//2022.6.1 LBZ 修复mask字符串包含/:时乱码的Bug
      DefaultFormatSettings.TimeSeparator:=':';//2022.6.1 LBZ 修复mask字符串包含/:时乱码的Bug
      {$endif}

    第3种终极方法:
    后来继续查找问题的根源,经多日debug,最终发现问题的根源是fpc的fpcsrc/packages/rtl-extra/src/unix/clocale.pp单元function FindSeparator(const s: string; Def: char): utf8char的FindSeparator:=s[i]引起的,当s值为中文日期格式时FindSeparator:=s[i]返回错误的分隔符,按以下方法修改就可以返回正确的分隔字符(将修改后的clocale.pp拷贝到lazarus/ide文件夹),重新编译就可以(此Bug已提交官方,希望官方能修正):

      function FindSeparator(const s: string; Def: char): utf8char;
      var
        i: integer;
        ss:string;
      begin
        FindSeparator := Def;
        i := Pos('%', s);
        if i=0 then
          Exit;
        inc(i);
        SkipModifiers(s, i);
        inc(i);
        if i<=Length(s) then
        //  FindSeparator:=s[i];
          ss:=UTF8Copy(s,i,1);
        if (ss='年') or (ss='月') or (ss='日') then
          FindSeparator := Def
        else
          if (ss='时') or (ss='分') or (ss='秒') then
            FindSeparator := Def
        else
          FindSeparator:=s[i];
      end;

    然后重新编译lazarus,设计时显示就正常了,推荐使用第3种方法。


  • 相关阅读:
    spring guides
    Go 汇编入门
    go内存管理
    websocket
    Scheduling In Go
    log-structured-merge-trees
    InfluxDB 内部机制解析
    thread-states
    MySQL高可用方案
    Amazon Aurora解读
  • 原文地址:https://www.cnblogs.com/qiufeng2014/p/16329567.html
Copyright © 2020-2023  润新知