Solved

RichEdit - detecting RTF ot Text format

Posted on 1998-09-07
3
342 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
3 Comments
 
LVL 4

Accepted Solution

by:
itamar earned 40 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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