Thread View: borland.public.delphi.rtl.general
5 messages
5 total messages
Started by Rolf Frei
Sun, 05 Nov 2006 16:35
FileMode and TextFile not working?
Author: Rolf Frei
Date: Sun, 05 Nov 2006 16:35
Date: Sun, 05 Nov 2006 16:35
32 lines
1815 bytes
1815 bytes
I have the following procedure to open an TextFile in readonly mode, but it
seems not to work. It looks as the FileMode variable doesnt work with
TextFile. I get all teh time an I/O error 32 for a textfile openend by Excel
at the same time. Ist this correct and if so, how can I open a TextFile in
R/O mode, to read teh file if it is open by another application?
procedure OpenReadOnlyTextFile(var F: TextFile; FileName: String);
begin
AssignFile(F, Filename);
FileMode := fmOpenRead;
try
try
Reset(F);
except
on E: EInOutError do
begin
E.Message := RFSysErrorString(E.ErrorCode) + '. (' + FileName + ')';
raise;
end;
on E: Exception do
begin
E.Message := E.Message + ' (' + FileName + ')';
raise;
end;
end;
finally
FileMode := fmOpenReadWrite;
end;
end;
Regards
Rolf
Re: FileMode and TextFile not working?
Author: Kurt Barthelmess [TeamB]
Date: Mon, 06 Nov 2006 09:04
Date: Mon, 06 Nov 2006 09:04
24 lines
1684 bytes
1684 bytes
"Rolf Frei" <nospam-rolf@nospam-eicom.ch> wrote: >I have the following procedure to open an TextFile in readonly mode, but it >seems not to work. It looks as the FileMode variable doesnt work with >TextFile. I get all teh time an I/O error 32 for a textfile openend by Excel >at the same time. Ist this correct and if so, how can I open a TextFile in >R/O mode, to read teh file if it is open by another application? You may not be able to. If Excel has the file open with exclusive rights, you can not get any access until it releases the file. You might try using a FileMode of: fmOpenRead or fmShareDenyNone That is the least restrictive and most accommodating access yu can request. If that does not work, Excel will have to relases the file first. Note that if Excel is modifying the file, the content of what you read is not guaranteed to be consistent. Good luck. Kurt
Re: FileMode and TextFile not working?
Author: Peter Below TeamB
Date: Mon, 06 Nov 2006 19:19
Date: Mon, 06 Nov 2006 19:19
23 lines
1665 bytes
1665 bytes
Rolf Frei wrote: > I have the following procedure to open an TextFile in readonly mode, > but it seems not to work. It looks as the FileMode variable doesnt > work with TextFile. Correct. The Reset routine opens a Textfile for read only access, but it still uses a share mode that does not allow another program to open the file. You can open the file in the mode you want using a TFilestream. You can then create a TStringlist and use its LoadFromStream method to load the file contents of processing at your leisure. This way you can specify fmReadOnly OR fmShareDenyNone as access, for example. -- Peter Below (TeamB) Don't be a vampire (http://slash7.com/pages/vampires), use the newsgroup archives : http://www.tamaracka.com/search.htm http://groups.google.com http://www.prolix.be
Re: FileMode and TextFile not working?
Author: Jon Grewer
Date: Sun, 03 Dec 2006 14:33
Date: Sun, 03 Dec 2006 14:33
27 lines
1877 bytes
1877 bytes
I am unable to find fmReadOnly in SysUtils (D7). Is is present in
another unit?
The actual modes present are:
const
{ File open modes }
{$IFDEF MSWINDOWS}
fmOpenRead = $0000;
fmOpenWrite = $0001;
fmOpenReadWrite = $0002;
fmShareCompat = $0000 platform; // DOS compatibility mode is not
portable
fmShareExclusive = $0010;
fmShareDenyWrite = $0020;
fmShareDenyRead = $0030 platform; // write-only not supported on all
platforms
fmShareDenyNone = $0040;
{$ENDIF}
thanks,
--Jon G.
Peter Below (TeamB) wrote on 11/06/2006 :
> You can open the file in the mode you want using a TFilestream. You can
> then create a TStringlist and use its LoadFromStream method to load the
> file contents of processing at your leisure. This way you can specify
> fmReadOnly OR fmShareDenyNone as access, for example.
Re: FileMode and TextFile not working?
Author: Wayne Niddery [TeamB]
Date: Sun, 03 Dec 2006 17:49
Date: Sun, 03 Dec 2006 17:49
13 lines
1335 bytes
1335 bytes
Jon Grewer wrote: > I am unable to find fmReadOnly in SysUtils (D7). Is is present in > another unit? > fmOpenRead = $0000; Use that. -- Wayne Niddery - Winwright, Inc (www.winwright.ca) "Bandwagons are like streetcars, there'll be another along in a few minutes."
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads