program RegTweak;

uses
  Registry,
  IniFiles,
  SysUtils,
  Forms,
  Dialogs,
  Controls,
  Classes;

type
  TDataType = (dtString, dtInteger, dtBool);

var
  Reg: TRegistry;
  Ini: TIniFile;
  IniName, DataTypeStr, Entry: String;
  DataType: TDataType;
  Sections, Entries: TStrings;
  Loop1, Loop2: Integer;

begin
  IniName := Application.ExeName;
  IniName := Copy(IniName, 1, Length(IniName) - 3) + 'INI';
  Ini := TIniFile.Create(IniName);
  Sections := TStringList.Create;
  Entries := TStringList.Create;
  Reg := TRegIniFile.Create;
  try
    if MessageDlg('Update registry with INI file settings?',
      mtConfirmation, [mbOK, mbCancel], 0) = mrOk then
    begin
      Ini.ReadSections(Sections);
      for Loop1 := 0 to Sections.Count - 1 do
      begin
        Entries.Clear;
        Ini.ReadSectionValues(Sections[Loop1], Entries);
        //Identify target registry entry type
        DataTypeStr := Entries.Values['Type'];
        DataType := dtString;
        if DataTypeStr <> '' then
          case UpCase(DataTypeStr[1]) of
            'I': DataType := dtInteger;
            'B': DataType := dtBool;
            'S': DataType := dtString;
          end;
        //Open the key
        Reg.OpenKey(Sections[Loop1], True);
        try
          //Set each entry
          for Loop2 := 0 to Entries.Count - 1 do
          begin
            Entry := Entries.Names[Loop2];
            //Skip the data type entry
            if UpperCase(Entry) <> 'TYPE' then
              case DataType of
                dtString: Reg.WriteString(Entry, Entries.Values[Entry]);
                dtInteger: Reg.WriteInteger(Entry,
                  StrToInt(Entries.Values[Entry]));
                dtBool: Reg.WriteBool(Entry,
                  UpperCase(Entries.Values[Entry]) = 'TRUE');
              end
          end
        finally
          Reg.CloseKey
        end
      end
    end
  finally
    Sections.Free;
    Entries.Free;
    Reg.Free;
    Ini.Free
  end
end.