CopyFile lazarus / 62-General ---------------------------------------------------------------------- Weitentaaal · 2021-02-08 10:20 Hello Guys Tried to do CopyFile (wanted to create a Save File as .. ). now i need to write my own copyfile, bc the existing one is opening the source file with sharedenywrite right in it, so as long as you have the file open it will not be able to open it. How do i rewriteCopyFile ? Thanks ---------------------------------------------------------------------- Bart · 2021-02-08 11:48 What exactly do you want to do? Is there a need to have the source file open read/write? If you know that your own program is the only process that has the source file open (with write permission) than simply open the file with "fmOpenRead or fmShareDenyNone". The actual copying is basic stuff, I take it that you can implement that yourself? I have a rather elaborate FileCopy routine that provides a callback for e.g. a progressbar. I use it for my backup program (so I trust the code). That one uses fmShareDenyWrite also (there is af course a reason for that: if you copy the first block and then some other process rewrites that, your copy may become invalid to the point it cannot be read by the application you designed it for). You're free to change that. You can find it at http://svn.code.sf.net/p/flyingsheep/code/trunk/Mij nLib/fsifileutils.pp. Bart ---------------------------------------------------------------------- Weitentaaal · 2021-02-08 12:00 Thanks for ur Reply i just wanted to create an operation wich allows the user to save his progress (a sqlite database) its a MainMenu with a Tab "Save As.." and if u click it it should create a Copy of the db(wich can later be reopened again). But i get the Error "Already open", bc my Application uses the File. So i wanted to change the sharedenywrite property or whatever to ShareDenyNone. Bad Idea ? LG ? and i still can't figure out how to override Functions wich are already implemented by a Lazarus Lib. f.eg. "CopyFile" Thanks ---------------------------------------------------------------------- Bart · 2021-02-08 12:11 A more simple approach would be to close the database, do the copy, re-open the database. Especially with a databse I would not recommend copying it if any proces has write access to it. Bart ---------------------------------------------------------------------- Weitentaaal · 2021-02-08 12:39 Ok that makes it easier. Thanks Bart. What could happen if db is still open and u try to copy the File ? ---------------------------------------------------------------------- Bart · 2021-02-08 12:42 The DB engine could update the sourcefile (perhaps in OnIdle or similar). At that point the integrity of the target file is comprimised: it will not be a 1-on-1 copy of the source file. Bart ---------------------------------------------------------------------- Zvoni · 2021-02-08 13:00 Depending on the Data in this SQLite-DB (Is this "progress" just one Table? Do i have to keep track of PrimaryKeys/Foreign Keys? etc.) i'd rather try for a series of SQL-Statements in a second Connection ("CREATE DATABASE", "CREATE TABLE", "INSERT INTO TABLE" blablabla) EDIT: Or use the Backup-API https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupinit ---------------------------------------------------------------------- Weitentaaal · 2021-02-08 14:32 Thanks Guys