Bug in function TXLSStream.OpenFileStreamRead

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
steven2009
Posts: 3
Joined: Wed Apr 25, 2012 12:04 pm

Bug in function TXLSStream.OpenFileStreamRead

Post by steven2009 »

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;
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Bug in function TXLSStream.OpenFileStreamRead

Post by larsa »

Hello

I don't understand. You click a cancel button and after that you call OpenFileStreamRead and it generates an exception (because you called it with an empty string?). What do you excpect shall happend?
If you call OpenFileStreamRead with an invalid filename there will be an exception.
Lars Arvidsson, Axolot Data
Post Reply