• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

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.
0
moonrise
Asked:
moonrise
1 Solution
 
itamarCommented:
Hi,

before calling the LoadFromFile method, read the file with Read function.

If the first line contains the string
{\rtf1\
 it's a RTF.

IHTH
0
 
viktornetCommented:
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
0
 
moonriseAuthor Commented:
Thank you both.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now