?
Solved

RichEdit - detecting RTF ot Text format

Posted on 1998-09-07
3
Medium Priority
?
347 Views
Last Modified: 2013-11-22
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
Comment
Question by:moonrise
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
itamar earned 160 total points
ID: 1338919
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1338920
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
 

Author Comment

by:moonrise
ID: 1338921
Thank you both.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question