代码之家  ›  专栏  ›  技术社区  ›  RBA

delphi 7 richedit和罗马尼亚语

  •  0
  • RBA  · 技术社区  · 15 年前

    我正在尝试将一些罗马尼亚文本写入RichEdit组件(delphi7),甚至我将Font属性-Charset设置为“EASTEUROPE\u Charset”也不起作用。

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

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

    有什么想法吗?

    3 回复  |  直到 6 年前
        1
  •  3
  •   Cosmin Prund    15 年前

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

    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。 当然,唯一真正的解决方案是切换到Delphi2009或Delphi2010,并在所有地方使用Unicode。

        2
  •  3
  •   RBA    15 年前

    我已经和绝地的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;
    
        3
  •  2
  •   Chris Thornton    15 年前

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