Recent

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

Pixy

  • New Member
  • *
  • Posts: 49
[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: 5154
  • 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: 14373
  • Sensorship about opinions does not belong here.
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 »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
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!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Pixy

  • New Member
  • *
  • Posts: 49
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: 4219
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/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018