Board index » delphi » EFOpenError with message 'Cannot open file.....'

EFOpenError with message 'Cannot open file.....'

I'm having problems with one of my programs.
Its loading wave files into memory via a memorystream (ms)

  ms.free;
  ms := tmemorystream.create;
  ms.clear;
  ms.loadfromfile(WaveFile);

  WaveFile is a string, taken from an OpenDialog.Filename
It only has one file in memory at any one time, but loads multiple files at
multiple points during runtime.

The first time it loads any file, its ok.
Some files it is fine with.  Other files always produce an error when loaded
for the second (and further) times:

"Project Speech.exe raised exception class EFOpenError with message 'Cannot
open file d:\My Documents\Jon2-1.wav'"

However, it's fine with something like d:\My Documents\Jon1-2.wav

Any ideas?

Cheers
Jonathan

 

Re:EFOpenError with message 'Cannot open file.....'


Hi !

Are you sure you closed the file ?
One solution might be to open the file in mode

  fmOpenRead or fmShareDenyNone,

allowing for opening more handles on the same file. It can be done with
TFileStream,  so you may modify TMemoryStream's LoadFromFile method, changing
the filemode parameter and turn it intu a flat procedure:

procedure LoadFromFileIntoMemStream(const FileName: string; MemStream:
TMemoryStream);
var
  Stream: TFileStream;
begin
  Stream:=TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
  try
    MemStream.LoadFromStream(Stream);
  finally
    Stream.Free;
  end;
end;

...good luck !

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

The Seed News skrev i meldingen <89s53p$9u...@lure.pipex.net>...

Quote
>I'm having problems with one of my programs.
>Its loading wave files into memory via a memorystream (ms)

>  ms.free;
>  ms := tmemorystream.create;
>  ms.clear;
>  ms.loadfromfile(WaveFile);

>  WaveFile is a string, taken from an OpenDialog.Filename
>It only has one file in memory at any one time, but loads multiple files at
>multiple points during runtime.

>The first time it loads any file, its ok.
>Some files it is fine with.  Other files always produce an error when loaded
>for the second (and further) times:

>"Project Speech.exe raised exception class EFOpenError with message 'Cannot
>open file d:\My Documents\Jon2-1.wav'"

>However, it's fine with something like d:\My Documents\Jon1-2.wav

>Any ideas?

>Cheers
>Jonathan

Re:EFOpenError with message 'Cannot open file.....'


Thanks for that - it now appears to work perfectly (after much trial & error
and a lot of {*word*193} memory errors...)

Cheers
Catfish

Quote
"Bj?rge S?ther" <REMOVE_bsaet...@online.no> wrote in message

news:Maiw4.6772$6b1.107583@news1.online.no...
Quote
> Hi !

> Are you sure you closed the file ?
> One solution might be to open the file in mode

>   fmOpenRead or fmShareDenyNone,

> allowing for opening more handles on the same file. It can be done with
> TFileStream,  so you may modify TMemoryStream's LoadFromFile method,
changing
> the filemode parameter and turn it intu a flat procedure:

> procedure LoadFromFileIntoMemStream(const FileName: string; MemStream:
> TMemoryStream);
> var
>   Stream: TFileStream;
> begin
>   Stream:=TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
>   try
>     MemStream.LoadFromStream(Stream);
>   finally
>     Stream.Free;
>   end;
> end;

> ...good luck !

> --
> Bjoerge Saether
> Consultant / Developer
> Asker, Norway
> bsaether.removet...@online.no (remove the obvious)

> The Seed News skrev i meldingen <89s53p$9u...@lure.pipex.net>...
> >I'm having problems with one of my programs.
> >Its loading wave files into memory via a memorystream (ms)

> >  ms.free;
> >  ms := tmemorystream.create;
> >  ms.clear;
> >  ms.loadfromfile(WaveFile);

> >  WaveFile is a string, taken from an OpenDialog.Filename
> >It only has one file in memory at any one time, but loads multiple files
at
> >multiple points during runtime.

> >The first time it loads any file, its ok.
> >Some files it is fine with.  Other files always produce an error when
loaded
> >for the second (and further) times:

> >"Project Speech.exe raised exception class EFOpenError with message
'Cannot
> >open file d:\My Documents\Jon2-1.wav'"

> >However, it's fine with something like d:\My Documents\Jon1-2.wav

> >Any ideas?

> >Cheers
> >Jonathan

Other Threads