unit funciones;

interface

function RtfToText(Cadena: PChar): PChar; cdecl; export;

implementation

uses
  Forms, Classes, SysUtils, StdCtrls, ComCtrls,
  Menus, Windows;

function RtfToText(Cadena: PChar): PChar;
var
  AStream : TStringStream;
  ARichEdit: TRichEdit;
begin
  ARichEdit := TRichEdit.CreateParented(HWND_MESSAGE);
  try
    AStream := TStringStream.Create(Cadena);
    try
      ARichEdit.SelectAll;
      ARichEdit.SelText := StrPas(Cadena);
      Result := PChar(ARichEdit.Text);
    finally
       FreeAndNIL(AStream);
    end;
  finally
    FreeAndNIL(ARichEdit);
  end;
end;

{ANTIGUA FUNCION CON FUGA DE MEMORIA
function RtfToText(Cadena: PChar): PChar;
var
  AStream : TStringStream;
  ARichEdit: TRichEdit;
begin
  AStream := TStringStream.Create(Cadena);
  ARichEdit := TRichEdit.CreateParented(HWND(-3));
  try
    ARichEdit.SelectAll;
    ARichEdit.SelText := StrPas(Cadena);
    Result := PChar(ARichEdit.Text);
  finally
    FreeAndNIL(AStream);
  end;
end;
}

end.
