Bug in function TXLSStream.OpenFileStreamRead
Posted: Mon May 21, 2012 3:38 am
When i click a button to open a excel, and then click the cancel button in the file searching dialog. It would run an error "raised exception class EFOpenError with message 'Cannot open file'. 'system can not find the path'". I found that the error was in "function TXLSStream.OpenFileStreamRead" in the unit XLSStream4. I have inserted try and except sentense to it, but it still run the same error. So could any experts help me to solve this problem. Thank you very much.
function TXLSStream.OpenFileStreamRead(const Filename: string): TExcelVersion;
var
Header: TBIFFHeader;
begin
//try
Result := xvNone; //the error existed
CloseStorage;
FStream := TFileStream.Create(Filename,fmOpenRead);
FStreamSize := FStream.Size;
FStream.Read(Header,SizeOf(TBIFFHeader));
if (Header.RecID and $FF) = BIFFRECID_BOF then begin
case (Header.RecID and $FF00) of
$0000: Result := xvExcel21;
$0200: Result := xvExcel30;
$0400: Result := xvExcel40;
end;
end;
FStream.Seek(0,soFromBeginning);
//except
//Exit;
//end;
end;
function TXLSStream.OpenFileStreamRead(const Filename: string): TExcelVersion;
var
Header: TBIFFHeader;
begin
//try
Result := xvNone; //the error existed
CloseStorage;
FStream := TFileStream.Create(Filename,fmOpenRead);
FStreamSize := FStream.Size;
FStream.Read(Header,SizeOf(TBIFFHeader));
if (Header.RecID and $FF) = BIFFRECID_BOF then begin
case (Header.RecID and $FF00) of
$0000: Result := xvExcel21;
$0200: Result := xvExcel30;
$0400: Result := xvExcel40;
end;
end;
FStream.Seek(0,soFromBeginning);
//except
//Exit;
//end;
end;