Link to home
Start Free TrialLog in
Avatar of moonrise
moonrise

asked on

RichEdit - detecting RTF ot Text format

I wrote a small word processor using TRichEdit. I want the users to be able to open RTF documents and Text document without having to specify the type themselves.  If I set the RichEdit to one type and try to open the other type I get errors.

Is there a way to look at a file before opening it and see if it is plain text or RTF.
ASKER CERTIFIED SOLUTION
Avatar of itamar
itamar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Itamar is right =)

Probably this is the only way to check that....Just to help you with the coding....

function rtf(Filename : string):Boolean;
var
  F : TextFile;
  Line : string;
begin
  AssignFile(f, Filename);
  Reset(F);
  ReadLn(f, Line);
  Result := Pos('{\rtf1\', Line);
  CloseFile(F);
end;

Example Call:

If RTF('C:\windows\desktop\test.txt') then
//Set it for rtf
else
  //Set it not for rtf

Hope this helps =)

Regards,
Viktor Ivanov
Avatar of moonrise
moonrise

ASKER

Thank you both.