View Issue Details

IDProjectCategoryView StatusLast Update
0035023FPCFCLpublic2020-04-01 12:48
ReporterBart Broersma Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86_64OSLinux Mint 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0035023: TRegIniFile.OpenKey does not update FCurrenPath correctly
DescriptionConsider this code snippet (copied from 0035022)

function CreateTestEntry: Boolean;
const
  BoolStr: array[Boolean] of String = ('False','True');
  OKStr: array[Boolean] of String = ('FAIL','OK');
var
  RegIni: TRegIniFile;
  B: Boolean;
  function TryOpenKey(Key: String; CanCreate: Boolean): Boolean;
  begin
    Result := RegIni.OpenKey(Key, CanCreate);
    writeln(format('OpenKey(''%s'',%s): %s',[Key,BoolStr[CanCreate],OkStr[Result]]));
  end;

begin
  Result := False;
  RegIni := TRegIniFile.Create('\Software');
  try
    writeln('CurrentPath=',RegIni.CurrentPath);
    B := RegIni.CreateKey('FPCTEST');
    writeln('CreateKey=',B);
    if not B then Exit;

    if not TryOpenKey('FPCTEST',False) then Exit;
    writeln('CurrentPath=',RegIni.CurrentPath);

    if not TryOpenKey('RegIni',True) then Exit;
    writeln('CurrentPath=',RegIni.CurrentPath);
    Result := True;
  finally
    RegIni.Free;
  end;
end;

var
  B: Boolean;
begin
  B := CreateTestEntry;
  writeln('CreateTestEntry=',B);
end.
Steps To ReproduceBuild and run the program on Windows.

Expected output (tested with Delphi 7):
CurrentPath=Software
CreateKey=TRUE
OpenKey('FPCTEST',False): OK
CurrentPath=Software\FPCTEST
OpenKey('RegIni',True): OK
CurrentPath=Software\FPCTEST\RegIni

Output of FPC trunk:
CurrentPath=Software
CreateKey=TRUE
OpenKey('FPCTEST',False): OK
CurrentPath=SoftwareFPCTEST <<--
OpenKey('RegIni',True): OK
CurrentPath=SoftwareFPCTESTRegIni <<--
TagsNo tags attached.
Fixed in Revision44478
FPCOldBugId
FPCTarget3.2.0
Attached Files

Relationships

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

Activities

Bart Broersma

2019-02-06 13:00

reporter  

winreg.inc.diff (511 bytes)   
Index: /devel/fpc/trunk/packages/fcl-registry/src/winreg.inc
===================================================================
--- /devel/fpc/trunk/packages/fcl-registry/src/winreg.inc	(revision 40745)
+++ /devel/fpc/trunk/packages/fcl-registry/src/winreg.inc	(working copy)
@@ -230,7 +230,7 @@
     end;                     
   If Result then begin
     if RelativeKey(Key) then
-      S:=CurrentPath + Key
+      S:=CurrentPath + '\' + Key
     else
       S:=UTF8Encode(u);
     ChangeKey(Handle, S);
winreg.inc.diff (511 bytes)   

Bart Broersma

2019-02-06 13:00

reporter   ~0113899

Last edited: 2019-02-06 13:11

View 3 revisions

Sorry, I selected wrong profile form the dropwdownlist, it must be:
Platform: i386, OS Win10, Version: 10
Can sombody change that please?

Possible patch for the issue attached (winreg.inc.diff).

Bart Broersma

2019-02-06 13:27

reporter   ~0113902

Last edited: 2019-02-06 13:39

View 2 revisions

Maybe an additional check for (Key<>'') and (CurrentPath<>'') and (CurrentPath[Length(CurrentPath)]<>'\') must be done before inserting the backslash?
(The registry can handle double backslashes though.)

Attached as winreg.inc.2.diff

Bart Broersma

2019-02-06 13:39

reporter  

winreg.inc.2.diff (639 bytes)   
Index: packages/fcl-registry/src/winreg.inc
===================================================================
--- packages/fcl-registry/src/winreg.inc	(revision 40745)
+++ packages/fcl-registry/src/winreg.inc	(working copy)
@@ -230,7 +230,12 @@
     end;                     
   If Result then begin
     if RelativeKey(Key) then
-      S:=CurrentPath + Key
+        begin
+          if (Key>'') and (CurrentPath>'') and (CurrentPath[Length(CurrentPath)]<>'\') then
+            S:=CurrentPath + '\' + Key
+          else
+            S:=CurrentPath + Key;
+        end
     else
       S:=UTF8Encode(u);
     ChangeKey(Handle, S);
winreg.inc.2.diff (639 bytes)   

Bart Broersma

2019-02-06 19:33

reporter   ~0113905

Sorry: attached reginifile.opensection.currentpath.diff does belong to another issue.
Please delete it (I can't).

Bart Broersma

2019-03-02 18:16

reporter   ~0114579

Please apply patch from 0035022 (it include the fix for this issue).

Michael Van Canneyt

2020-04-01 09:15

administrator   ~0121814

Fixed using patch in 0035022

Issue History

Date Modified Username Field Change
2019-02-06 12:09 Bart Broersma New Issue
2019-02-06 13:00 Bart Broersma File Added: winreg.inc.diff
2019-02-06 13:00 Bart Broersma Note Added: 0113899
2019-02-06 13:03 Bart Broersma Note Edited: 0113899 View Revisions
2019-02-06 13:11 Bart Broersma Note Edited: 0113899 View Revisions
2019-02-06 13:27 Bart Broersma Note Added: 0113902
2019-02-06 13:39 Bart Broersma File Added: winreg.inc.2.diff
2019-02-06 13:39 Bart Broersma Note Edited: 0113902 View Revisions
2019-02-06 19:31 Bart Broersma File Added: reginifile.opensection.currentpath.diff
2019-02-06 19:33 Bart Broersma Note Added: 0113905
2019-02-09 15:17 Marco van de Voort File Deleted: reginifile.opensection.currentpath.diff
2019-03-02 18:16 Bart Broersma Note Added: 0114579
2020-04-01 09:14 Michael Van Canneyt Relationship added related to 0035022
2020-04-01 09:15 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-04-01 09:15 Michael Van Canneyt Status new => resolved
2020-04-01 09:15 Michael Van Canneyt Resolution open => fixed
2020-04-01 09:15 Michael Van Canneyt Fixed in Version => 3.3.1
2020-04-01 09:15 Michael Van Canneyt Fixed in Revision => 44478
2020-04-01 09:15 Michael Van Canneyt FPCTarget => 3.2.0
2020-04-01 09:15 Michael Van Canneyt Note Added: 0121814
2020-04-01 12:48 Bart Broersma Status resolved => closed