View Issue Details

IDProjectCategoryView StatusLast Update
0033980FPCFCLpublic2020-04-01 12:47
ReporterBart Broersma Assigned ToMichael Van Canneyt  
Status closedResolutionfixed 
Product Version3.1.1 
Fixed in Version3.3.1 
Summary0033980: TRegIniFile: failure on consecutive reads when Section parameter is empty
DescriptionWhen you do consecutive reads (like ReadString) on the same key/section/ident, and the Section paramter is an empty string, then the second (and following) reads will fail.
Steps To ReproduceBuild and run the following program:

program rtest;

{$apptype console}
{$ifdef fpc}{$mode objfpc}{$endif}

  registry, sysutils, classes {$ifndef fpc}, windows{$endif};

  RegIni: TRegIniFile;
  WFileName: String;
  i: Integer;
  RegIni := TRegIniFile.Create('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', KEY_READ);
    for i := 1 to 2 do
      WFileName := RegIni.ReadString ('', 'Desktop', 'Failure!');
      writeln(format('Try %d: WFileName = "%s"',[i,WFileName]));

Build and run with fpc

C:\Users\Bart\LazarusProjecten\bugs\Console\regini>fpc rtest.lpr
Free Pascal Compiler version 3.1.1 [2018/06/03] for i386
Try 1: WFileName = "C:\Users\Bart\Desktop"
Try 2: WFileName = "Failure!"

Now build and run with Delphi (D7)

C:\Users\Bart\LazarusProjecten\bugs\Console\regini>dcc32 rtest.lpr
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
Try 1: WFileName = "C:\Users\Bart\Desktop"
Try 2: WFileName = "C:\Users\Bart\Desktop"
Additional InformationOriginally reported in forum:,41847.0.html by user BjPascal.
TagsNo tags attached.
Fixed in Revision44478
Attached Files


related to 0035022 closedMichael Van Canneyt TRegIniFile.WriteString writes to wrong Key 


Bart Broersma

2018-07-13 16:54

reporter   ~0109430

Last edited: 2018-07-18 13:08

View 2 revisions

Maybe Section should not be closed if it is empty string?
(Probably for both reading and writing)

Michael Van Canneyt

2018-08-21 16:21

administrator   ~0110199

I don't have windows, so it is hard to test.
The testprogram works not at all on Linux, I did test that.
So whenever I again work a little under Windows, I will look at this.
(unless someone else fixes it first)

Bart Broersma

2018-08-21 16:27

reporter   ~0110200

Where is the test program?
I don't mind fixing/testing.
It's just that I hardly ever use TRegistry and never in my life used TRegIniFile.
I can also hardly find any Delphi examples (with expectd output).

Michael Van Canneyt

2018-08-21 16:31

administrator   ~0110201

Ehm. it's in the bug description ?

Bart Broersma

2018-08-21 16:47

reporter   ~0110203

When you mentioned test program I hoped there was a testprogram somewhere in fpc's tests.
So, I misunderstood you.

There are many methods that call CloseSection, most of them I don't really know how they should behave.
Probably the same issue exists for consecutive writes.

I'll keep on testing when I have time.
That'll be on Windows.
Hope I don't screw up my registry.

I sincerely hope nobody of sound mind uses this on a non-Windows platform...

Michael Van Canneyt

2018-08-21 17:07

administrator   ~0110205

I don't even use the registry on Windows, so my experience is limited.

jamie philbrook

2018-08-22 02:59

reporter   ~0110224

In this example, not defining a section in the ReadString does nothing.

I can't even see how it works the first time?
Looking at the code below..
createSection is set to false because it isn't specified in the

function TRegIniFile.OpenSection(const Section: string; CreateSection : Boolean = false): boolean;
  k: HKEY;
  S : String;

  If (S<>'') and (S[1] = '\') then
  if CreateSection then
  if Section <> '' then
    if k = 0 then

It looks like it simply skips all of this and never actually "Getkey"

Not sure what would happen if you would use a '\' instead of an empty section in the call? It would at least call the GetKey function..

Bart Broersma

2019-03-02 18:16

reporter   ~0114580

Please see patch from 0035022, it will fix this issue.

Michael Van Canneyt

2020-04-01 09:11

administrator   ~0121813

Resolved using patch in 0035022, thanks !

Issue History

Date Modified Username Field Change
2018-07-13 16:51 Bart Broersma New Issue
2018-07-13 16:54 Bart Broersma Note Added: 0109430
2018-07-18 13:08 Bart Broersma Note Edited: 0109430 View Revisions
2018-08-21 16:21 Michael Van Canneyt Note Added: 0110199
2018-08-21 16:27 Bart Broersma Note Added: 0110200
2018-08-21 16:31 Michael Van Canneyt Note Added: 0110201
2018-08-21 16:47 Bart Broersma Note Added: 0110203
2018-08-21 17:07 Michael Van Canneyt Note Added: 0110205
2018-08-22 02:59 jamie philbrook Note Added: 0110224
2019-03-02 18:16 Bart Broersma Note Added: 0114580
2020-04-01 09:10 Michael Van Canneyt Relationship added related to 0035022
2020-04-01 09:11 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-04-01 09:11 Michael Van Canneyt Status new => resolved
2020-04-01 09:11 Michael Van Canneyt Resolution open => fixed
2020-04-01 09:11 Michael Van Canneyt Fixed in Version => 3.3.1
2020-04-01 09:11 Michael Van Canneyt Fixed in Revision => 44478
2020-04-01 09:11 Michael Van Canneyt FPCTarget => 3.2.0
2020-04-01 09:11 Michael Van Canneyt Note Added: 0121813
2020-04-01 12:47 Bart Broersma Status resolved => closed