【问题标题】:delphi 7 richedit and romanian languagedelphi 7 Richedit和罗马尼亚语
【发布时间】:2010-07-20 08:29:25
【问题描述】:

我正在尝试将一些罗马尼亚语文本写入 RichEdit 组件(Delphi 7),即使我将字体属性 - 字符集设置为“EASTEUROPE_CHARSET”,它也不起作用。

我想要完成的是在 RichEdit 中粘贴一些文本(罗马尼亚语),加载到 StringList 中,将属性顺序设置为 true 并将其分配给另一个 RichEdit 组件(按字母顺序对列表进行排序)。

我知道这在 Delphi2009 及更高版本中应该不是问题,但此时我只能使用 Delphi 7。

单词示例:opoziţie,computerizată。

有什么想法吗?

最好的问候,

【问题讨论】:

  • 这个论坛帖子可能会有所帮助:看起来你的未来有问题:sicomponents.com/forum/…
  • 是的,但是我已经从那里完成了所有工作......并且问题与某些组件有关,当我使用 Borland 套件中的标准 TRichEdit 组件时......,最好的问候,
  • 你能解释一下它是怎么不工作的吗?我刚刚在 Windows XP 上使用我的 Delphi 7 副本进行了测试,它正在工作(对我来说)。您是对所有罗马尼亚语变音符号有问题,还是仅对 Ş 和 Ţ 有问题?什么版本的 Windows(不幸的是它很重要)。我假设非 unicode 应用程序的默认代码页在您的计算机上不是罗马尼亚语,是吗? (您可以在控制面板、区域和语言设置、高级选项卡中看到)
  • Cosmin,我试图私下联系你,但似乎我不能...它不起作用,因为我正在粘贴...richedits 中的文本已经没有变音符号...我正在使用 win 2003 服务器 SP2,但应用程序将在 XP 上运行。

标签: delphi multilingual richedit


【解决方案1】:

试试这个代码,它从 RichEdit1 中读取文本为 UNICODE 文本,手动将 S 和 T + Comma 转换为 S 和 T + Cedilla,然后使用 WideCharToMultiByte 将文本转换为代码页 1250。代码点转换需要完成是因为代码页 1250 仅编码基于 cedilla 的 Ş 和 Ţ 版本,而 Vista 和 Windows 7 下的新罗马尼亚语键盘生成(正确)基于逗号的 Ş 和 Ţ 版本!

procedure TForm1.Button1Click(Sender: TObject);
var GetTextStruct:GETTEXTEX;
    GetLenStruct:GETTEXTLENGTHEX;
    RequiredBytes:Integer;
    NumberOfWideChars:Integer;
    WideBuff:PWideChar;
    AnsiBuff:PChar;
    i:Integer;
begin
  ;

  // Get length of text
  GetLenStruct.flags := GTL_NUMBYTES or GTL_USECRLF or GTL_PRECISE;
  GetLenStruct.codepage := 1200; // request unicode
  RequiredBytes := SendMessage(RichEdit1.Handle, EM_GETTEXTLENGTHEX, Integer(@GetLenStruct), 0);

  // Prepare structure to get all text
  FillMemory(@GetTextStruct, SizeOf(GetTextStruct), 0);
  GetTextStruct.cb := SizeOf(GetTextStruct);
  GetTextStruct.flags := GT_USECRLF;
  GetTextStruct.codepage := 1200; // request unicode

  WideBuff := GetMemory(RequiredBytes);
  try
    // Do the actual request
    SendMessage(RichEdit1.Handle, EM_GETTEXTEX, Integer(@GetTextStruct), Integer(WideBuff));
    // Replace the "new" diactrics with the old (make Romanian text compatible with code page 1250)
    NumberOfWideChars := RequiredBytes div 2;
    for i:=0 to NumberOfWideChars-1 do
    case Ord(WideBuff[i]) of
      $0218: WideBuff[i] := WideChar($015E);
      $0219: WideBuff[i] := WideChar($015F);
      $021A: WideBuff[i] := WideChar($0162);
      $021B: WideBuff[i] := WideChar($0163);
    end;
    // Convert to code-page 1250
    RequiredBytes := WideCharToMultiByte(1250, 0, WideBuff, -1, nil, 0, nil, nil);
    AnsiBuff := GetMemory(RequiredBytes);
    try
      WideCharToMultiByte(1250, 0, WideBuff, -1, AnsiBuff, RequiredBytes, nil, nil);
      Memo1.Lines.Text := AnsiBuff; // AnsiBuff now contains the CRLF-terminated version of the
                                    // text in RichEdi1, corectly translated to code page 1250
    finally FreeMemory(AnsiBuff);
    end;
  finally FreeMemory(WideBuff);
  end;

end;

然后使用类似的东西将 AnsiString 转换为 UNICODE 并推入 RichEdit。 当然,唯一真正的解决方案是切换到 Delphi 2009 或 Delphi 2010 并全部使用 Unicode。

【讨论】:

    【解决方案2】:

    我已经用 Jedi 的 JvWideEditor 解决了这个问题。代码如下

    procedure TForm2.SortUnicode;
    var asrt:TWStringList;
        i:Integer;
    begin
     JvWideEditor1.Lines.Clear;
     JvWideEditor2.Lines.Clear;
     asrt:=TWStringList.Create;
     if OpenDialog1.Execute then
      begin
       wPath:=OpenDialog1.FileName;
       JvWideEditor1.Lines.LoadFromFile(wPath,[foUnicodeLB]);
       try
       asrt.AddStrings(JvWideEditor1.Lines);
       for i:=asrt.Count-1 downto 0 do 
        begin
          if Trim(asrt.Strings[i])='' then
           asrt.Delete(i);
        end;
       asrt.Duplicates:=dupAccept;
       asrt.CaseSensitive:=true;
       asrt.Sorted:=True;
    
       JvWideEditor2.Lines.AddStrings(asrt);
       JvWideEditor2.Lines.SaveToFile(GetCurrentDir+'\res.txt',[foUnicodeLB]);
       finally
        FreeAndNil(asrt);
       end;
      end;
    end;
    

    【讨论】:

    • 如果您卡在 D7 上,还请查看 TNT 组件集。你真的应该转移到 D2010 并使用完整的 Unicode 字符串。
    【解决方案3】:

    检查 Windows 中的语言设置。如果您正在运行英文窗口,请尝试将“将非 unicode 程序视为...”设置为罗马尼亚语。或者,在本机罗马尼亚 Windows 上运行。要在混合环境中运行(需要同时显示不同的字符集),您可能需要 Unicode。

    【讨论】:

    • 所以,除了在 d2009 或 2010 上编写应用程序之外,我没有其他解决方案,所以我可以使用 Unicode...欢迎任何其他解决方案...最好的问候,
    • 罗马尼亚语版本的 Windows 在罗马尼亚很少见,我们所有的罗马尼亚程序员都需要让我们的程序在罗马尼亚语版本的 Windows 和英语版本上运行。问题是,我们没有罗马尼亚语的 Windows 95。 XP 拿到罗马尼亚版时,只有 Pro 版,而不是 Home,而且 Enhlish Pro 比罗马尼亚 Pro 便宜。然后是大型 OEM 生产商,他们不为罗马尼亚市场生产 PC 版本,所以我们大部分时间都预装了英文版的 Windows。一点都不好笑!
    猜你喜欢
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多