Win to Linux, INI file issues lazarus / 32-Linux ---------------------------------------------------------------------- iru · 2014-01-25 09:36 Gentlefolk, Environment: Linux mint 16, Laz 1.0.14. I have a program which was developed in the windows environment and I am moving it to Linux.. I have sorted out issues with accessing the .INI file. Can find the file. However all "ReadString(
, , '') return the '' default value. Checked case of sections and items, all look OK. Read the code in "inifiles", cant see anything there. Any ideas, anyone? Ian ---------------------------------------------------------------------- BigChimp · 2014-01-25 09:42 Guess: run dos2unix on it in advance to change CRLF to LF line endings? Can't remember having to do that with ini files shared across windows and linux... but my memory is sometimes not that good ---------------------------------------------------------------------- iru · 2014-01-25 10:46 Thank you for the response. Your are probably correct, it would have to be something like that and I would never have thought of it. I say probably because after installing Dos2Unix I come back to the lazarus ide and all I get is errors. Reboot and I cannot even launch Lazarus. The error message is "cannot luanch application" One step forward, two steps backward, or something like that...... iru ---------------------------------------------------------------------- iru · 2014-01-25 11:00 Gentlefolk, Some research shows that most of /usr/share/lazarus/1.0.14 has disappeared, only directories examples, tools and tmp exist. Dos2Unix was installed by means of the Software Manager, all appeared normal. Several steps backwards..... Ian. ---------------------------------------------------------------------- iru · 2014-01-25 11:11 Gentlefolk, Reinstalled Laz from a .deb debian version. Installed correctly, clicked on icon on the desktop and Laz started and there we were, project files open and all. Compiled clean. Ran the program and stepped through the code. Same problem, no results on a  ini read string. One step forward.... Ian. ---------------------------------------------------------------------- Leledumbo · 2014-01-25 13:58 Rebuild IniFiles with debug info, then debug and step into ReadString. ---------------------------------------------------------------------- Bart · 2014-01-25 22:41 Show us some code and the ini, otherwise it's hard to tell. Maybe you have soe diacrtics in either section or item? Bart ---------------------------------------------------------------------- iru · 2014-01-26 02:46 Gentlefolk, Re-compiled IniFiles so I could step through the code. The answer is simple, in the TIniFile.Create a test is made to see if the .ini file is accessible. If it is accessible the contents are set up for further processing, if not nothing is set up. Any further processing like a  ReadString simply exits because a variable "Count" is = 0. I had the .ini file name correct but  had not prefixed it with the path (In windows it would have worked because of the "current" directory). Fixed, thanks for the interest and help, Ian. ---------------------------------------------------------------------- Leledumbo · 2014-01-26 06:48 QuoteI had the .ini file name correct but  had not prefixed it with the path (In windows it would have worked because of the "current" directory).Unfortunately the wiki is currently down. When it's up, you can see multiplatform programming guide on *nix section. There's nothing such as "current directory" in *nix. Your OS is free to set the current directory to anywhere for whatever reason (security maybe?). ---------------------------------------------------------------------- User137 · 2014-01-26 06:55 Quote from: Leledumbo on January 26, 2014, 07:48:32 amUnfortunately the wiki is currently down. When it's up, you can see multiplatform programming guide on *nix section. There's nothing such as "current directory" in *nix. Your OS is free to set the current directory to anywhere for whatever reason (security maybe?).I haven't programmed with Linux much, but are you telling that i can't do something like this in Linux? Code: [Select]stringList.LoadFromFile('File.txt');... where File.txt would be in same folder as executable? You can change location of executable in project options, which might be going to '/lib/' folder. Some Lazarus versions made weird default values to this. I would at least look for a way to SetCurrentDirectory to application folder first, before adding program paths to all other commands that handle filenames. ---------------------------------------------------------------------- edvard · 2014-01-26 09:15 http://lazarus- ccr.sourceforge.net/docs/rtl/sysutils/getcurrentdir.html http://lazarus- ccr.sourceforge.net/docs/rtl/sysutils/setcurrentdir.html http://wiki.freepascal.org/TString_List-TString_Tutorial Works here on Linux: Code: [Select]program new_program; {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Classes, sysutils; var   stringList: TStringList;   i: integer;   begin   stringList := TStringlist.Create;   try     stringList.LoadFromFile('File.txt'); // stringList.LoadFromFile(GetCurrentDir+'/File.txt'); // this works too     Writeln('Lines in file: ',stringList.Count);     for i := 0 to (stringList.Count-1) do     Writeln(stringList[i]);   finally     stringList.Free;   end; end. Just remember Linux is case-sensitive even if Pascal/Lazarus isn't, and you must include the forward-slash before the file name because GetCurrentDir doesn't include it. ---------------------------------------------------------------------- Leledumbo · 2014-01-26 10:09 QuoteI haven't programmed with Linux much, but are you telling that i can't do something like this in Linux?Exactly, unless you run it from terminal. In that case, the current directory is respected AFAIK. The problem usually arises from running the application by double clicking in the file manager. EDIT: The wiki is up again, here's the article: http://wiki.lazarus.fr eepascal.org/Multiplatform_Programming_Guide#On_Unix_there_is_no_.22ap plication_directory.22