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;
TRichViewEdit - Opening an RTF File
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.