* * *

Author Topic: 'Unable to create file' when outside lazarus  (Read 2180 times)

mike parr

  • New member
  • *
  • Posts: 12
'Unable to create file' when outside lazarus
« on: July 01, 2010, 05:33:06 am »
Hi  - I'm writing a text editor(on ubuntu) - I click  a button and it throws up  a save dialog, and writes some text to a file.  it runs fine under lazarus.
But when I run  the app outside lazarus (by double-clicking on the name) the program works up to the point of trying to save the file, giving the error:

    Unable to create file /home/mine/  .... the file name

I wondered if I am not setting an option in the IDE for free-standing execution?

thanks
Mike

Bart

  • Hero Member
  • *****
  • Posts: 794
    • Bart en Mariska's Webstek
Re: 'Unable to create file' when outside lazarus
« Reply #1 on: July 01, 2010, 07:00:29 am »
Please give exact errormessage.
Also investigate what the value is of GetLasOSError if the error occurs.

Something like:

Code: [Select]
  try
    ...
    //save the file
  except
    on E: Exception do ShowMessage(E.Message + ' (#' + IntToStr(GetLastOSError) + ')' );
  end;
  ...

And post the code you use for writing to the file.

Bart

mike parr

  • New member
  • *
  • Posts: 12
Re: 'Unable to create file' when outside lazarus
« Reply #2 on: July 01, 2010, 09:36:27 am »
Thanks for the advice, Bart.   Much appreciated.

I tried a different approach - ran it with sudo - and it worked ok. (I also run laz as root). I recall that ubuntu has a unique approach to working as root, and this is the area I will look into.  I'm guessing that my problem is more ubuntu than lazarus.

mike


Bart

  • Hero Member
  • *****
  • Posts: 794
    • Bart en Mariska's Webstek
Re: 'Unable to create file' when outside lazarus
« Reply #3 on: July 01, 2010, 01:33:40 pm »
Let me guess.

You run lazarus as root. Run the program from within Lazarus, create the file.
Now the file is owned by root.

Then you run the program as normal user  (by double-clicking on the name, as you said) , you try to rewrite the file that already exists, but that file is owned by root and cannot be written to by a normal user.

Change the ownership of the file to yourself (being normal user), something like

Code: [Select]
sudo chown <your username> <the filename in question>

Bart

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads