RichText (Unicode) -> Plain-Text (Unicode)

Tinitus

Premium
Регистрация
14 Ноя 2010
Сообщения
63
Реакции
3
Credits
61
Добрый день,

подскажете пожалуйсто какой лучший способ получить PlainText (Unicode) из RichText (Unicode).

Поточнее: до сих пор моя БД была ANSI. Теперь переставляю на Unicode. До сих пор пользовался одной функцией, которая доставляла PlainText из RichText. Так-как теперь я задаю Unicode-Text в мой RichEdit, эта функция больше не работает.

Поэтому ищу другую возможность экстраировать Plain-UnicodeText из RTF-UnicodeText.

Был-бы очень рад, если кто-нибудь смог помочь.

Работаю с Delphi XE.

------------

Hi,

I'm looking for a way to extract the PlainText (Unicode) out of a RTF-Text (Unicode).

To be more precise:
so far my database was in ANSI. Now I'm switching to Unicode. So far I was using a function, which was delivering the PlainText (ANSI) out of a RTF-Text (ANSI). Since I'm typing in my text in Unicode into my RichEdit, the function doesn't work anymore.

That's why I', looking for another way to extract the Plain-UnicodeText our of the RTF-UnicodeText.

Would be great, if someone coule help out and point our possible solutions.

I'm working on Delphi XE.
 
Последнее редактирование модератором:

jik

Турист
Регистрация
19 Авг 2008
Сообщения
4
Реакции
1
Credits
8
Попробуй такой вариант:

Код:
function GetRTF(RE: TRichedit): String;
var
  GetTextStruct: GETTEXTEX;
  GetLenStruct: GETTEXTLENGTHEX;
  NumChars: Integer;
  Buff: Pointer;
begin
  Result := '';
  // Get length of text
  FillMemory(@GetLenStruct, SizeOf(GetLenStruct), 0);
  GetLenStruct.flags := GTL_NUMCHARS or GTL_USECRLF or GTL_PRECISE;
  GetLenStruct.codepage := 1200; // request unicode
  NumChars := SendMessage(RE.Handle, EM_GETTEXTLENGTHEX,
Integer(@GetLenStruct), 0);
  if NumChars <> E_INVALIDARG then
  begin
    // Prepare structure to get all text
    FillMemory(@GetTextStruct, SizeOf(GetTextStruct), 0);
    GetTextStruct.cb := (NumChars + 1) * SizeOf(WideChar); // include room
for a null terminator
    GetTextStruct.flags := GT_USECRLF;
    GetTextStruct.codepage := 1200; // request unicode
    Buff := GetMemory(GetTextStruct.cb);
    try
      // Do the actual request
      NumChars := SendMessage(RE.Handle, EM_GETTEXTEX,
Integer(@GetTextStruct), Integer(Buff));
      if NumChars > 0 then
        SetString(Result, PWideChar(Buff), NumChars);
    finally
      FreeMemory(Buff);
    end;
  end;
end;
 

Tinitus

Premium
Регистрация
14 Ноя 2010
Сообщения
63
Реакции
3
Credits
61
Спасибо большое, работает отлично!

Единственное что я изменил: вместо (RE: TRichedit) я сразу передаю (Handle: THandle) как параметер, потому-что я пользуюсь двумя разными RichEdit-компонентами, но и это сработало, спасибо!