嘗試此代碼,它將RichEdit1中的文本作爲UNICODE文本讀取,手動將S和T + Comma轉換爲S和T + Cedilla,然後使用WideCharToMultiByte將文本轉換爲代碼頁1250.代碼點轉換需要因爲代碼頁1250只編碼Ş和c的基於cedilla的版本,而Vista和Windows 7下的新羅馬尼亞鍵盤生成(正確)Ş和com的基於逗號的版本!
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。
這個論壇的帖子可能會幫助:好像你在你的未來的問題,但:http://www.sicomponents.com/forum/viewtopic.php?t=299&sid=71eb99aaafec45eae4dcb8e135898c78 – Tobiasopdenbrouw 2010-07-20 10:36:30
是的,但我已經做了一切從那裏...和問題是有關的一些組件,當我使用Borland套件的標準TRichEdit組件.., 最好的問候, – RBA 2010-07-20 11:22:14
你能解釋如何它不工作?我剛剛在Windows XP上測試了我的Delphi 7副本,並且它正在工作(對我而言)。您是否遇到過所有羅馬尼亞語變音符號問題,或者您只是在使用Ş和problems時遇到問題?什麼版本的Windows(不幸的是它很重要)。我假設您的計算機上的非Unicode應用程序的默認代碼頁不是羅馬尼亞語,是嗎? (你可以看到,在控制面板,區域和語言設置,高級選項卡) – 2010-07-20 12:08:42