* * *

Author Topic: File Locked  (Read 1287 times)

C#R#

  • New member
  • *
  • Posts: 40
File Locked
« on: November 03, 2016, 02:25:02 pm »
Hi,

I have a lot of orginal database files, and select one to see and change with OpenDialog1.
I make copy of original database file to another, to avoid changes on original file (sqlite3)
It's working fine on linux, but on windows no.
DatasetEventos.filename always = 'showing', to get a easy way.
On windows, at first time the copy 'showing' works fine, but if I open another file, the file 'showing' is locked, but I have DatasetEventos.close before copy !!! 
Anybody know why ?

Thanks.


Code: Pascal  [Select]
  1.       Form1.DatasetEventos.close;
  2.  
  3.        if OpenDialog1.execute then begin
  4.  
  5.  
  6.        path :=  ExtractFileDir(OpenDialog1.FileName) + {$IFDEF WINDOWS} '\' {$ELSE} '/' {$ENDIF}  ;
  7.  
  8.        FileUtil.CopyFile(OpenDialog1.FileName, path + 'showing',[cffOverwriteFile],false);
  9.  
  10.  

Thaddy

  • Hero Member
  • *****
  • Posts: 3669
Why do the Danish always try to fuck up any programming language?

C#R#

  • New member
  • *
  • Posts: 40
Re: File Locked
« Reply #2 on: November 03, 2016, 06:38:50 pm »
Hi Thaddy, thank you for repply !

The problem is not a name, look:

1) Run the application
2) select a file to open
3) copy the file selected to another, with name 'showing'
4) open and edit 'showing' (sqlite3)  (at this point, the app show a graphic of data)
5) close 'showing'
6) go to 2 <---  at this time, on windows, 'showing' is locked by the OS, and the
next FileUtil.CopyFile will fail, if I try to delete 'showing' while the application is open, I get a error message.
On linux, I have no problems.

Thanks !

lainz

  • Hero Member
  • *****
  • Posts: 1864
  • Nace una flor, todos los días sale el sol...
    • BGRABitmap
Re: File Locked
« Reply #3 on: November 03, 2016, 07:07:58 pm »
Code: Pascal  [Select]
  1. {$IFDEF WINDOWS} '\' {$ELSE} '/' {$ENDIF}

There is 'PathDelim' also..

About the error, it happens very often, the error is that the file gets locked because an application is using it (at least it says windows). There is a program called unlocker that unlocks the file for you, but is not working well under windows 10, at least for me.

Of course you need a solution that does not involve a third party application, the only thing I need to do always this happens is restart the PC and then delete that file or folder.

Check this, files can be deleted on reboot:
https://www.raymond.cc/blog/why-are-you-asked-to-restart-after-install-or-uninstall-software/

lainz

  • Hero Member
  • *****
  • Posts: 1864
  • Nace una flor, todos los días sale el sol...
    • BGRABitmap
Re: File Locked
« Reply #4 on: November 03, 2016, 07:21:53 pm »
When you copy the file use another name, so doesn't matter if get's blocked or not is a different file and you will have no problems.

Showing1
Showing2
ShowingN

C#R#

  • New member
  • *
  • Posts: 40
Re: File Locked
« Reply #5 on: November 03, 2016, 07:51:23 pm »
Hi  Lainz,

That's it, if I use a new name at a time, will never get an error.
but I don't know how many times the user will go back to open file...
I need to process a filter on the data recorded, and show it on a graphic, but I can not lost another informations
on the record, then I think in copying the file to edit informations securely.
I have one file by day, recording the status of process... to many files...
I will empty 'showing' (delete * from table) and copy record by record from another dataset... (maybe... %) )

Thanks!

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus