TRichViewEdit - Opening an RTF File
Posted: Fri Feb 08, 2013 11:19 am
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;
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;