Recent

Author Topic: TRegIniFile raises exception  (Read 13598 times)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TRegIniFile raises exception
« Reply #15 on: July 15, 2018, 06:33:46 pm »
Filed as issue #33993.

Bart
« Last Edit: July 15, 2018, 07:20:33 pm by Bart »

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TRegIniFile raises exception
« Reply #16 on: August 28, 2020, 11:27:00 am »
I have got this code from a Delphi source:

Code: Pascal  [Select][+][-]
  1. ...
  2. uses ... registry...
  3. ...
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var Ini:TRegIniFile;
  6. begin
  7.   Ini := TRegIniFile.Create('Test Reg Entry');
  8.   Ini.WriteString('General Settings', 'GenSet1', 'GenSet1a');
  9.   Ini.WriteString('General Settings', 'GenSet2', 'GenSet2a');
  10.   Ini.Free; //Lazarus crashes on ini.free
  11. end;    

It works fine, the values are written in registry, but it crashes on Ini.Free. Could it be a bug in Lazarus?
I am using Lazarus 2,0,10; W10 64bit;FPC3,2,0;rev 63525.
« Last Edit: August 28, 2020, 12:47:16 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TRegIniFile raises exception
« Reply #17 on: August 28, 2020, 03:16:26 pm »
Please try this in a pure fpc program, no dependencies on LCL/Lazarus/Lazutils.

If it crashes, also try with fpc trunk.

B.t.w. Using TRegIniFile in modern times is a bit weird.
It was introduced when MS introduced the registry, to make porting ini-file settings into the registry a little bit easier. That is now > 20 years ago.
If you need to use the registry, use TRegistry instead (which also kind of works on non-Windows platforms, whereas TRegIniFile is flawed beyond repair on such platforms).

Bart
« Last Edit: August 28, 2020, 03:20:12 pm by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TRegIniFile raises exception
« Reply #18 on: August 28, 2020, 09:13:26 pm »
Code: Pascal  [Select][+][-]
  1. uses
  2.   registry;
  3.  
  4. var
  5.   Ini: TRegIniFile;
  6. begin
  7.   Ini := TRegIniFile.Create('fpc_reginifile_test');
  8.   Ini.WriteString('aSection', 'aIdent', 'aValue');
  9.   Ini.WriteSTring('aOtherSection','aOtherIdent','aOtherValue');
  10.   Ini.Free;
  11. end.

Does not crash with either fpc 3.2.0 or fpc trunk.

With 3.2.0 it does not properly write the key/value pairs though, it does with trunk.
It seems that rr44477 wasn't merged to 3.2.0 (it is in fixes 3.2 though).

Bart
« Last Edit: August 28, 2020, 09:47:09 pm by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TRegIniFile raises exception
« Reply #19 on: August 28, 2020, 09:16:04 pm »
Also no crash with the same code inside a Lazarus (trunk) event handler.

Bart

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TRegIniFile raises exception
« Reply #20 on: August 29, 2020, 09:29:40 am »

Thanks, so I will just have to wait, until there is an official release with the fix.

B.t.w. Using TRegIniFile in modern times is a bit weird.
Some of the tools used in our company are written in Delphi. One of them needs improvement, so I got the Delphi code and I got it conveted to Lazarus, but s.o. might try to merge my changes in the Delphi source (they do not have a license for me, AFAIK it is extremely expensive).
If it was up to me I would never write anything in the registry, since this is okay nether with portablility, nor with non-Windows.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: TRegIniFile raises exception
« Reply #21 on: August 29, 2020, 02:29:18 pm »
Thanks, so I will just have to wait, until there is an official release with the fix.

You don't have to wait as you could:

1) Download the source and compile the FPC fixes 3.2 branch; or
2) Patch the FPC 3.2.0 release and re-compile.

Use the source, Luke :)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TRegIniFile raises exception
« Reply #22 on: August 29, 2020, 10:22:36 pm »
Some of the tools used in our company are written in Delphi. One of them needs improvement, so I got the Delphi code and I got it conveted to Lazarus

It would probably be rather simple to rewrite this to use TRegistry instead.
This should then also work in Lazarus.

Bart

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TRegIniFile raises exception
« Reply #23 on: August 31, 2020, 04:59:58 pm »
You don't have to wait as you could:

1) Download the source and compile the FPC fixes 3.2 branch; or
2) Patch the FPC 3.2.0 release and re-compile.
..
Thanks, I would do it in the older days, when I was much more aware and dependent on Lazarus.
Now this just sounds me like a few hours of googling and reading manuals, I cannot afford to spend that time.


Years ago there used to be nightly build of Lazarus, but they stopped being built.
« Last Edit: August 31, 2020, 05:01:35 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TRegIniFile raises exception
« Reply #24 on: May 19, 2021, 03:03:02 pm »
Hi again.
Lazarus Version 2.0.12, date 2021-04-06; FPC 3.2.0; SVN 64642.


Same code on Win10, 64 bit:
Code: Pascal  [Select][+][-]
  1.  
  2. {$MODE Delphi}
  3. ...
  4. uses
  5.   ...registry;
  6. ...
  7. procedure TForm1.Button1Click(Sender: TObject);
  8. var
  9.   Ini: TRegIniFile;
  10. begin
  11.   Ini := TRegIniFile.Create('fpc_reginifile_test');
  12.   Ini.WriteString('aSection', 'aIdent', 'aValue');
  13.   Ini.WriteSTring('aOtherSection','aOtherIdent','aOtherValue');
  14.   Ini.Free;
  15. end;  



It creates in HKEY_CURRENT_USER a key (folder) fpc_reginifile_test, and another subkey fpc_reginifile_test in it and inside it creates two subkeys aSection and aOtherSection.
This does not seem okay to me?

Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TRegIniFile raises exception
« Reply #25 on: May 19, 2021, 03:22:00 pm »
Please test with fpc trunk.

As a side note: TRegIniFile was created long, long time ago to ease the transition from using ini-files to using the registry (win 3.x -> win 95).
Affter more than 25 year, one might expect developers to use TRegistry directly.

The fpc implementation of TRegInifile has been flawed for many, many years and, while it would build for non windows platforms as well, it was so utterly broken on those platforms that it's use is now deprecated and TRegIniFile (and TRegistrIniFile, which is a pointless wrapper around TRegIniFile) are removed for that platform in the future (fpc 4.0).

Bart

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TRegIniFile raises exception
« Reply #26 on: May 20, 2021, 02:20:49 pm »
Thanks, since TRegIniFile is gonna be killed, I have rewritten the necessary parts to use TRegistry, using
Code: Pascal  [Select][+][-]
  1. {$ifndef fpc}  //Delphi
  2. ... TRegitryIni
  3. {$ELSE} //Lazarus    
  4. ... TRegistry
  5. {$ENDIF}  
.
Hopefully, that will not make compiling back in Delphi impossible.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TRegIniFile raises exception
« Reply #27 on: May 20, 2021, 06:53:17 pm »
TRegistry is (supposed to be) Delphi compatible.
So if the Lazarus TRegistry code works OK, it should also work in Delphi.

Bart

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: TRegIniFile raises exception
« Reply #28 on: May 20, 2021, 07:07:47 pm »
Code: Text  [Select][+][-]
  1. uses
  2.   ...registry;
  3. ...
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var
  6.   Ini: TRegIniFile;
  7. begin
  8.   Ini := TRegIniFile.Create('fpc_reginifile_test');
  9.   Ini.WriteString('aSection', 'aIdent', 'aValue');
  10.   Ini.WriteSTring('aOtherSection','aOtherIdent','aOtherValue');
  11.   Ini.Free;
  12. end;
It creates in HKEY_CURRENT_USER a key (folder) fpc_reginifile_test, and another subkey fpc_reginifile_test in it and inside it creates two subkeys aSection and aOtherSection.
This does not seem okay to me?

Why do you think this is wrong? TRegIniFile is like an ini file, only inside the registry. When you create a TIniFile you create a file with the name given as parameter; when you create a TRegInifile you create a node inside the registry with the name given as parameter. When you write a string to TInifile you have the first parameter as section inside the ini, and the second parameter is the value below this section. The same with TRegIniFile: it adds a node with the name of the first parameter and an item from the second parameter as value.

I tried your code on Delphi - it does the same as Lazarus.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TRegIniFile raises exception
« Reply #29 on: May 20, 2021, 07:20:26 pm »
@wp:
Look at the attached file in post #24
The structure added is like:
Code: [Select]
-fpc_reginifile_test
 |-fpc_reginifile_test
   |-aSection
   |-aOtherSection

Notice the double "fpc_reginifile_test".

It should not do that, but it does not do that anymore on my fpc 3.2.2RC1.
CM630 is using fpc 3.2.0, and I do recall that there was such a bug in TRegIniFile, and that it was fixed.
It seems the fix already is in the 3.2.2!

Bart

 

TinyPortal © 2005-2018