0

In a Delphi 10 Seattle console application with no visible console window, I need to extract plain text from a .RTF file. So I wrote this code:

procedure ExtractPlainTextFromRTFFile(const ARTFFile, OutputTextFile: string);
var
  RE: Vcl.ComCtrls.TRichEdit;
begin
  RE := Vcl.ComCtrls.TRichEdit.Create(nil);
  try
    RE.Lines.LoadFromFile(ARTFFile);
    TFile.WriteAllText(OutputTextFile, RE.Text);
  finally
    RE.Free;
  end;
end;

However this creates an error at run-time:

EInvalidOperation with message Control has no parent window

since TRichEdit needs a parent window.

So how can I extract plain text from .RTF file in a Delphi console application?

user1580348
  • 5,721
  • 4
  • 43
  • 105
  • 2
    Ken, I found the solution in this question page: http://stackoverflow.com/questions/3227899/using-trichedit-at-runtime-without-defining-a-parent – user1580348 Apr 07 '16 at 13:04
  • @Deltics, in that case you should reopen the question and have it closed with the proper duplicated added. – Johan Apr 08 '16 at 13:12
  • @Johan - at the time I could only vote to re-open (I don't have the ability to unilaterally re-open). But now only one more vote was needed to re-open, so I was able to use my vote to achieve the desired result. Done. The correct duplicate **is** now identified and I shall remove my previous comment to avoid any confusion in the future. :) – Deltics Apr 10 '16 at 23:20
  • @Deltics, great, now order has been restored to the universe ;-) – Johan Apr 10 '16 at 23:29

0 Answers0