Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can one manipulate files during Runtime? 2

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA

I need to manipulate (save/load) files.
Can this be done during Runtime?
I am using Delphi 6 Enterprise.

Anybody?
 
hi,

What kind of files you want to manipulate.

Steph [Bigglasses}
 
How silly of me! :) I might have mentioned ...

They are Paradox files. Being (say)
MyFile.db and
MyFile.px .

Perhaps I should mention that the reason for this is I want to be able to copy a particular file from a known folder into another known folder and (whilst doing so) rename it.
 
hi,

This makes more sense.

Use the commands RenameFile and MoveFile for renaming and moving files.

var
oldName, NewName: string;
begin
...
OldName := 'MyFile.db';
NewName := 'YourFile.db';
RenameFile(oldName, NewName)

MoveFile(Pchar(Oldname, Pchar('C:\History\' + copy
(OldName, 1, length(OldName) - 4) + '.BAK'));

end;

Renamefile just renames the file. With MoveFile you can move and rename a file.
OldName and NewName are of string type and can therefor contain complete mapping.

Steph [Bigglasses]



 
Huston! We have a problem!!

The following code works - in so far as a BreakPoint reveals that
all the proper values are in the required variables and I don't get
an exception.

But MoveFile doesn't achieve anything.

What am I missing?

var
UserName, DVTemp : String;
OldName, NewName: string;

begin
with dmConvert do
begin
UserName := tblSelStoreNLICENSEE.value;
DVTemp := tblSelStoreNDVTemp.value;
NewName := UserName + ' ' + DVTemp + '.db';
OldName := 'SelStore.db';
RenameFile(OldName, NewName);
MoveFile(PChar(NewName), PChar('C:\UserFiles\ES\Registrations\'));
end;
end;

 
hi,

Here houston.
In the movefile in the second parameter you donnt have the file name.
so it should read:

MoveFile(PChar(NewName), PChar('C:\UserFiles\ES\Registrations\'+NewName));

Steph [Bigglasses]
 
Steph.
You have been very helpful to me.

If you let me have your e-mail address - to delphiman@bigpond.com - I can send you a model by seperate e-mail of a solution to something you have a problem with.

Terry
 
Still no luck. Nothing happens.

I suspect the problem might be that the file in question is active. But then I expect Delphi to raise an exception.

I might add that what I should be doing is to copy the file to the required folder.

But in this connection I have found the folowing in Delphi Help ..

The runtime library does not provide any routines for copying a file. However, if you are writing Windows-only applications, you can directly call the Windows API CopyFile function to copy a file. Like most of the Delphi runtime library file routines, CopyFile takes a filename as
a parameter, not a Handle. When copying a file, be aware that the file attributes for the existing file are copied to the new file, but the security attributes are not. CopyFile is also useful when moving files across drives because neither the Delphi RenameFile function nor the Windows API MoveFile function can rename/move files
across drives.


Any idieas?
 
hi,

If the file is in use, active or under controle of one or more applications, the filemove wonn't work and there is no error message.

Steph [Bigglasses]
 
I think you can use copyfile even if the file is in use.
By the way, there is a .pas file in the delphi demos located at C:\Program Files\Borland\Delphi6\Demos\Doc\Filmanex\fmxutils.pas that contains a number of file related functions. One thing to remember is that the functions share names with the api calls, but with different parameters. The order in which the Windows unit and the fmxutils unit are listed in the calling unit will determine which one comes up if you use copyfile(). You can alleviate the problem by calling Windows.copyfile or fmxutils.copyfile. One benefit of the fmxutils is that you don't have to type pchar() for the string parameters.

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top