Solved

Filemodes with Assignfile and Reset

Posted on 2001-07-16
9
1,237 Views
Last Modified: 2012-05-04
Hi, Im using AssignFile and Reset in my application, and this seems to cause a problem. I need to be able to copy the opened files (for backup) when the application is running, and I cant do that! They are locked. I've looked at the global variable FileMode, but the default is already the least restricted, namely Read/Write. I could of course use a stream, and change all my calls, but it's a lot of calls... So, is it possible to open with other filemodes, when using Reset?

Pede
0
Comment
Question by:pede
9 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6285386
maybe it helps

if you open the file in readonly-mode
0
 
LVL 1

Author Comment

by:pede
ID: 6285410
I need to be able to write to the files, so that's not an option :0( I know this could cause problems if Im writing to the file while backing up, but it's not a huge problem in my application.


0
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 6285453
Hi,
I don't understand why you can't copy these files. Reset opens files for read/write but they are still readable by other apps (including copying).

Regards, Geo
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 2

Expert Comment

by:bugroger
ID: 6285476
HI,

I think the best will be to use

 CreateFile, Read/WriteFile, CloseHandle

and change all your calls !

GL
 BUG
0
 
LVL 1

Author Comment

by:pede
ID: 6285602
I cant copy the files using the program PcAnyWhere, thats why I thought they where opened in the wrong way. It seems that PcAnyWhere can't copy any files at all, if another progam are using them. I tried to make a new Word document, opened it with Word and made a copy of the file. No problems. Then I tried to copy it with PcAnyWhere, and it failed.

Points goes to Geobul, since his comment made me try this.

Pede
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6286367
Yeah I have been wondering about this myself. I am using Win 2000 and when I was using Win 98 I could use xcopy directly to backup the registry but in Win 2000 it doesn't work because the registry files are locked down. I have yet to find away to do it programmically but I know it is possible because the Win 2000 backup utility does it. So if anybody has a solution to this I will award 100 points to them myself. :>)


The Crazy One
0
 

Expert Comment

by:ms99
ID: 6287686
Hi Pede,

These constants control the way you open a file:

const fmOpenRead       = $0000;
const fmOpenWrite      = $0001;
const fmOpenReadWrite  = $0002;

const fmShareCompat    = $0000;
const fmShareExclusive = $0010;
const fmShareDenyWrite = $0020;
const fmShareDenyRead  = $0030;
const fmShareDenyNone  = $0040;

Besides opening for read/write you must also set Filemode to fmShareDenyNone or fmShareDenyWrite to let other applications read your files:

assignFile(f,'file.dat');
filemode := fmOpenReadWrite or fmShareDenyNone;
reset(f);


0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6288137
I didn't try it, but was just wondering... perhaps a MemoryStream can do it?
0
 
LVL 1

Author Comment

by:pede
ID: 6289028
Im sorry I forgot to assign the points, but the question is closed already. But some nice info there, ms99. The Delphi help didn't include all those constants.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 64
indy Tmemory stream non latin charcter issue 2 110
How to debug For loops? 3 49
how to update exe applicatio from internet ? 6 78
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question