[SOLVED]program not reading the ini file. lazarus / 32-Linux ---------------------------------------------------------------------- MadMike · 2021-09-07 12:39 hi, Curious behavior. Wrote and tested an application on a Raspberry Pi, and it accesses its ini file no problem. Ran the app. from the command prompt, no problem. Added a desktop entry and ran it from there, doesn't read the ini file. The ini is in the same directory as the app. Am I missing something? (Nearly posted this in the beginners section, because I am one!) thanks for any help mike ---------------------------------------------------------------------- balazsszekely · 2021-09-07 12:47 Quote from: MadMike on September 07, 2021, 02:39:09 pmhi, Curious behavior. Wrote and tested an application on a Raspberry Pi, and it accesses its ini file no problem. Ran the app. from the command prompt, no problem. Added a desktop entry and ran it from there, doesn't read the ini file. The ini is in the same directory as the app. Am I missing something? (Nearly posted this in the beginners section, because I am one!) thanks for any help mike Are you using relative of absolute path? Since you are running the application from a desktop entry, I would use absolute path, something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses IniFiles, LazFileUtils; //... var  MyIniFile: TIniFile;  Path: string;begin  Path := AppendPathDelim(ExtractFilePath(Application.ExeName)) + 'MyIni.ini';  MyIniFile := TIniFile.Create(Path);  try    //do something with ini  finally    MyIniFile.Free  end;end; ---------------------------------------------------------------------- MadMike · 2021-09-07 14:31 GetMem, Works a treat. Thanks very much. learning every day... Mike ---------------------------------------------------------------------- winni · 2021-09-07 14:49 Hi! Modern times:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ExtractFilePath(Application.ExeName) can now be replaced by Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Application.Location Winni ---------------------------------------------------------------------- MadMike · 2021-09-13 11:53 Quote from: winni on September 07, 2021, 04:49:49 pmHi! Modern times:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ExtractFilePath(Application.ExeName) can now be replaced by Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Application.Location Winni There always seems to be more than one way. Why is that do you think? Mike ---------------------------------------------------------------------- Zvoni · 2021-09-13 13:12 Quote from: MadMike on September 13, 2021, 01:53:01 pmThere always seems to be more than one way. Why is that do you think? Mike Because having/knowing only one way might get you end up in a Dead- end. It's always good to know, that you can take a left turn instead of going forward blind and get stuck. In this special case: FPC/Lazarus is cross-Platform There is no EXE on Linux..... ---------------------------------------------------------------------- dbannon · 2021-09-13 14:17 > The ini is in the same directory as the app. And, perhaps thats the underlying problem ? This is Linux, we don't do that here. Ultimately, when the rest of the world discovers how great your application is and everyone wants a copy, you will find that the binary (ie, what you might call the exe file) lives somewhere like /usr/bin and the config files live in $HOME/.config/$APPNAME/. You see, the binary is in a read only area and each individual user has their own separate config area. You cannot put the ini file up in /usr/bin because the app, running with your permissions, would not be able to change it. And other users might need different settings. So, following the binary back to where it lives hoping to find the ini file is a bad approach. And then there might be symlink issues .... This strict rule about where things go might seem over the top right now but you are better doing things correctly right from the start than having, at some stage, to backtrack. Davo ---------------------------------------------------------------------- MadMike · 2021-09-13 14:53 Quote from: dbannon on September 13, 2021, 04:17:09 pm> The ini is in the same directory as the app. And, perhaps thats the underlying problem ? This is Linux, we don't do that here. Ultimately, when the rest of the world discovers how great your application is and everyone wants a copy, you will find that the binary (ie, what you might call the exe file) lives somewhere like /usr/bin and the config files live in $HOME/.config/$APPNAME/. You see, the binary is in a read only area and each individual user has their own separate config area. You cannot put the ini file up in /usr/bin because the app, running with your permissions, would not be able to change it. And other users might need different settings. So, following the binary back to where it lives hoping to find the ini file is a bad approach. And then there might be symlink issues .... This strict rule about where things go might seem over the top right now but you are better doing things correctly right from the start than having, at some stage, to backtrack. Davo Seems to work now, but I'll go back and check the program can actually write to the ini! I have placed the program and its ini in /usr/local/bin. Is this a read only section? You are quite right in stating I should be doing things correctly: Following ''best practice". ---------------------------------------------------------------------- dbannon · 2021-09-13 23:57 > I have placed the program and its ini in /usr/local/bin. Is this a read only section? Yes Mike, anything starting with /usr should be read only.  If you can write to that as an ordinary user, you have security problems ! Even though you probably will not use your Pi as a multiuser system, you should always think of it that way. And putting your ini file in /usr/local/bin would make it visible to other users. Davo ---------------------------------------------------------------------- MadMike · 2021-09-14 10:02 Well thanks for everyone's help. All seems to be working now. I couldn't use the 'universal': Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Path:= AppendPathDelim('/$HOME/.config')+'MyIni.ini'; or even Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Path:= AppendPathDelim(ExtractFilePath('/$HOME/.config'))+'MyIni.ini'; I had to construct a more specific: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Path:= AppendPathDelim('/home/pi/.config')+'MyIni.ini'; The project is a Raspberry Pi - based piece of stand alone test equip (piece of pi?). Installation involves burning an SD card with an image so I can't foresee any problems. Hopefully. I'll have to read up more on extracting file paths for the next project. Mike ---------------------------------------------------------------------- dbannon · 2021-09-15 06:18 Mike, I am sorry, I did not realise no one mentioned - GetAppConfigDirUTF8(false); Works across all platforms quite reliably.  Its in LazUtils. Davo EDIT : You were on "a" right path anyway, its just you needed different syntax,  instead of - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  Path:= AppendPathDelim('/$HOME/.config')+'MyIni.ini'; you needed - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Path:= AppendPathDelim(GetEnvironmentVariable('HOME')) + '.config' + PathDelim + 'MyIni.ini'; Probably better to have a directory with the apps name down there. Davo ---------------------------------------------------------------------- MadMike · 2021-09-15 09:16 Thanks, More to read up on.  Boy, sooo much to learn Mike