Solved

RichEdit - detecting RTF ot Text format

Posted on 1998-09-07
3
339 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now