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.