Restore previously entered data on custom page next time Inno Setup-made installer is executed

前端 未结 1 629
半阙折子戏
半阙折子戏 2021-01-03 12:03

I want to use this code, but the part of the code to uninstall I need: in the next time I open the executable it can read the information written in this field \'Service nam

相关标签:
1条回答
  • 2021-01-03 12:17

    If I understand you correctly, you're looking for a way to fill an input field with the previously stored data. In the example that you linked you can notice that there is used the GetPreviousData function which is used just for reading data previously stored by the SetPreviousData function call.

    The principle is, that when the RegisterPreviousData event fires, you call the SetPreviousData function for each value that you want to store, providing for each value some unique key (parameter of this function is called ValueName which is not much self-explaining). For example here is how to store values from two different input fields:

    procedure RegisterPreviousData(PreviousDataKey: Integer);
    begin
      SetPreviousData(PreviousDataKey, 'MyUniqueKey1', InputPage.Values[0]);
      SetPreviousData(PreviousDataKey, 'MyUniqueKey2', InputPage.Values[1]);
    end;
    

    As I already mentioned, data stored this way you can read by using GetPreviousData function which you can call right after you add your input fields. Into this function you'll pass the same key as you used to store the data and except that you'll pass also the default value, which will be returned when the data for the given key won't be found. For the above code example it can be like this:

    procedure InitializeWizard;
    var
      Index: Integer;
    begin
      InputPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Description', '');
    
      Index := InputPage.Add('Input field 1:', False);
      InputPage.Values[Index] := GetPreviousData('MyUniqueKey1', 'Default value');
    
      Index := InputPage.Add('Input field 2:', False);
      InputPage.Values[Index] := GetPreviousData('MyUniqueKey2', 'Default value');
    end;
    

    This mechanism uses registry as a storage for values. To be more specific, it is the same key as where the uninstallation information are stored. Actually, what is passed by PreviousDataKey parameter of the RegisterPreviousData event method is a handle to the just created uninstallation data registry key, which is used to tell the SetPreviousData function where to store the data.

    Value keys in that registry key path are composed from the fixed Inno Setup CodeFile: prefix part followed by the unique key passed in the SetPreviousData function. So, for our example would Inno Setup create the following value keys in uninstallation data registry key path:

    Inno Setup CodeFile: MyUniqueKey1
    Inno Setup CodeFile: MyUniqueKey2
    
    0 讨论(0)
提交回复
热议问题