このコードを試してみてください。RichEdit1 からのテキストを UNICODE テキストとして読み取り、手動で S と T + Comma を S と T + Cedilla に変換してから、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 を使用することです。