Issues extracting text from RTF with TRichview 20
Posted: Mon Jan 03, 2022 1:43 pm
Hello,
I've installed the trial version of TRichView 20 and can't compile my project because of some issues with some helper functions, that were created with your help some time ago:
Can't find anything in the help file or in the announcement threads since version 18.0 (where it still worked).
I've installed the trial version of TRichView 20 and can't compile my project because of some issues with some helper functions, that were created with your help some time ago:
Code: Select all
type
TRTFConverter = class(TObject)
private
FParser: TRVRTFReader;
FFirstLine: Boolean;
FRTFText: TRVUnicodeString;
FStream: TStream;
procedure DoReaderText(Sender: TRVRTFReader; const Text: TRVAnsiString; Position: TRVRTFPosition);
procedure DoReaderUnicodeText(Sender: TRVRTFReader; const Text: TRVUnicodeString; Position: TRVRTFPosition);
public
constructor Create;
destructor Destroy; override;
function ExtractTextFromRTF(RTFContent: string): string;
end;
...
...
procedure TRTFConverter.DoReaderText(Sender: TRVRTFReader; const Text: TRVAnsiString;
Position: TRVRTFPosition);
var
TextW: TRVUnicodeString;
CodePage: Cardinal;
begin
if (Position <> rtf_ts_ContinuePara) and not FFirstLine then begin
FRTFText := FRTFText + #13#10;
end;
FFirstLine := False;
if Sender.FontTable.Count = 0 then begin
CodePage := CP_ACP;
end
else begin
CodePage := RVU_Charset2CodePage(Sender.FontTable[Sender.RTFState.CharProps.FontIndex].Charset);
end;
TextW := RVU_RawUnicodeToWideString(RVU_AnsiToUnicode(CodePage, Text));
FRTFText := FRTFText + TextW;
end;
procedure TRTFConverter.DoReaderUnicodeText(Sender: TRVRTFReader; const Text: TRVUnicodeString;
Position: TRVRTFPosition);
begin
if (Position <> rtf_ts_ContinuePara) and not FFirstLine then begin
FRTFText := FRTFText + #13#10;
end;
FFirstLine := False;
FRTFText := FRTFText + Text;
end;
function TRTFConverter.ExtractTextFromRTF(RTFContent: string): string;
var
lList: TStringList;
lBlobStream: TMemoryStream;
begin
FRTFText := '';
FFirstLine := True;
FParser := TRVRTFReader.Create(nil);
lList := TStringList.Create;
lBlobStream := TMemoryStream.Create;
try
lList.Text := RTFContent;
lList.SaveToStream(lBlobStream);
lBlobStream.Position := 0;
FParser.OnNewText := DoReaderText; <- Incompatible Types: 'TCustomRVMSWordReader' und 'TRVRTFReader'
FParser.OnNewUnicodeText := DoReaderUnicodeText; <- Incompatible Types: 'TCustomRVMSWordReader' und 'TRVRTFReader'
if FParser.ReadFromStream(lBlobStream) = rtf_ec_OK then begin <- Incompatible Types
Result := FRTFText;
end;
finally
FreeAndNil(lBlobStream);
FreeAndNil(lList);
FParser.Free;
end;
end;