Solved

Filemodes with Assignfile and Reset

Posted on 2001-07-16
9
1,246 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Downloading email attachments 2 83
Delphi inherited method 6 78
scroll down TListBox component in Delphi 1 30
Delphi, TImage, Png 2 17
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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 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