TRichViewEdit - Opening an RTF File

General TRichView support forum. Please post your questions here
Post Reply
Graham
Posts: 64
Joined: Sun Jan 27, 2013 7:51 pm
Location: Berkshire U.K.

TRichViewEdit - Opening an RTF File

Post by Graham »

If I have an RTF file open in Word and then try to open it with RichViewEdit, it gives an error. The modification below fixes the problem, but I can't see a way of letting the caller know that the file is now open for "Read Only". I have done a bodge to call the standard "OpenFile" API to determine what is going to happen before I call the RTF read function from RichViewEdit.

function TRVRTFReader.ReadFromFile(const AFileName: String): TRVRTFErrorCode;
var Stream: TFileStream;
begin
Result := rtf_ec_FileOpenError;
try
Stream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyWrite);

except
try
Stream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
except
Stream := nil;
end;
end;
if Stream<>nil then begin
Result := ReadFromStream(Stream);
Stream.Free;
end;
end;
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I think it's not a good idea to use fmShareDenyNone. What if the file will be modified while reading?
Graham
Posts: 64
Joined: Sun Jan 27, 2013 7:51 pm
Location: Berkshire U.K.

Post by Graham »

I take your point, but I would have thought it would be better to warn the user that the file is already open by another process and then give the user the choice of opening the file as ReadOnly. The RichEdit application would then force a SaveAs when the user tries to save any changes they may make.
Post Reply