delphi 7 richedit 和罗马尼亚语

发布于 2024-09-10 17:46:52 字数 325 浏览 6 评论 0原文

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

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

我知道这在 Delphi2009 及更高版本中不应该成为问题,但目前我只能使用 Delphi 7。

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

有什么想法吗?

此致,

I'm trying to write some Romanian text into a RichEdit component (Delphi 7) , and even i set the Font Property - Charset to "EASTEUROPE_CHARSET" it doesn't work.

What i want to accomplish is to paste some text (in romanian) in a RichEdit, load into a StringList, set the property order to true and assign it to another RichEdit component (sort the list in a alphabetical order).

I know this shouldn't be a problem in Delphi2009 and up, but at this point I can work only with Delphi 7.

word examples : opoziţie, computerizată.

Any ideas?

Best regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

莫多说 2024-09-17 17:46:52

尝试此代码,它从 RichEdit1 读取文本作为 UNICODE 文本,手动将 S 和 T + 逗号转换为 S 和 T + 变音符号,然后使用 WideCharToMultiByte 将文本转换为代码页 1250。需要完成代码点转换,因为代码第 1250 页仅对基于变音符号的 Ş 和 Ţ 版本进行编码,而 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。

Try this code, it reads the text from RichEdit1 as UNICODE text, manually converts S and T + Comma to S and T + Cedilla and then uses WideCharToMultiByte to convert the text to code page 1250. The code point conversions need to be done because code page 1250 only encodes the cedilla-based versions of Ş and Ţ, while the new Romanian keyboards under Vista and Windows 7 generate the (correct) comma-based versions of Ş and Ţ!

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;

Then use something similar to turn AnsiString into UNICODE and push into the RichEdit.
Of course, the only real solution is to switch to Delphi 2009 or Delphi 2010 and use Unicode all over.

空名 2024-09-17 17:46:52

我已经用 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;

i've resolved it with JvWideEditor from Jedi. Code is bellow

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;
冰火雁神 2024-09-17 17:46:52

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

Check the language settings in Windows. If you are running English windows, try setting the "treat non-unicode programs as..." to Romanian. Or, run on native Romanian Windows. To run in a mixed environment (needing to show different charsets simultaneously), you'll likely need Unicode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文