Recent

Author Topic: [RESOLVED] INI files  (Read 313 times)

Pixy

  • New member
  • *
  • Posts: 37
[RESOLVED] INI files
« on: April 26, 2019, 01:39:45 pm »
I want to load an already existing ini file in the same folder and read some values. I use:
Code: Pascal  [Select]
  1. var
  2.         IniFile1: TIniFile;
  3.         IniDir1: string;
  4.         a: string;
  5.  
  6. begin
  7.         IniDir1 := GetCurrentDir;
  8.         IniFile1 := TIniFile.Create(IniDir1 + 'Config.ini');
  9.         try
  10.         a := IniFile1.ReadString('User3', 'Clan', 'false');
  11.  
  12.         finally
  13.                 IniFile1.Free;
  14.         end;
  15. end;
  16.  

I get "Abstract error". From what I've read I understand that it is some kind of memory problem. Any ideas?
« Last Edit: April 26, 2019, 03:35:43 pm by Pixy »

Handoko

  • Hero Member
  • *****
  • Posts: 3084
  • My goal: build my own game engine using Lazarus
Re: INI files
« Reply #1 on: April 26, 2019, 01:59:37 pm »
Tested on Linux. The code you provided only will work correctly if you modify the line #8 to:

IniFile1 := TIniFile.Create(IniDir1 + '/' + 'Config.ini');

Thaddy

  • Hero Member
  • *****
  • Posts: 8163
Re: INI files
« Reply #2 on: April 26, 2019, 02:06:52 pm »
Don't use \/ or /\, but use DirectorySeparator...
https://www.freepascal.org/docs-html/rtl/system/directoryseparator.html

(And try to not use inifiles in the first place...., but that's another matter about bad habits)

Good practice is even for the blind to see if you know how to access the documentation....

(Handoko knows that... :D )
« Last Edit: April 26, 2019, 02:17:17 pm by Thaddy »
Read the manuals and if you are a professional get a proper education in computer science. Makes the forum a lot cleaner.

pixelink

  • Hero Member
  • *****
  • Posts: 916
    • Pixelink Media
Re: INI files
« Reply #3 on: April 26, 2019, 02:30:54 pm »
Here is a decent INI editor made in LAZ

It's not mine, but you can doanload the ZIp project towards middle of page.

https://forum.lazarus.freepascal.org/index.php?topic=13788.0
Can't Type - Forgetful - Had Stroke = Forgive this old man!


Pixelink Media •  Pixelink Forum
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

Pixy

  • New member
  • *
  • Posts: 37
Re: INI files
« Reply #4 on: April 26, 2019, 03:09:28 pm »
Here is a decent INI editor made in LAZ

It's not mine, but you can doanload the ZIp project towards middle of page.

https://forum.lazarus.freepascal.org/index.php?topic=13788.0

Interesting.

Tested on Linux. The code you provided only will work correctly if you modify the line #8 to:

IniFile1 := TIniFile.Create(IniDir1 + '/' + 'Config.ini');

Good to know. I'm using a custom compiler and I still get 'Abstract error'.

Don't use \/ or /\, but use DirectorySeparator...
https://www.freepascal.org/docs-html/rtl/system/directoryseparator.html

(And try to not use inifiles in the first place...., but that's another matter about bad habits)

Good practice is even for the blind to see if you know how to access the documentation....

(Handoko knows that... :D )

Heheh. In my case you are absolutely right. I'll have to find another way. I'll just read a simple .txt file and try to read the text. Is there documentation for that also?

lucamar

  • Hero Member
  • *****
  • Posts: 1792
Re: [RESOLVED] INI files
« Reply #5 on: April 26, 2019, 04:32:33 pm »
I tend to fall in that same trap with GetCurrentDir so now I always get it like this:
Code: Pascal  [Select]
  1. ThisDir := IncludeTrailingPathDelimiter(GetCurrentDir);
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.