Solved

Filemodes with Assignfile and Reset

Posted on 2001-07-16
9
1,230 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now