Inno Setup: Use data from custom wizard page in Registry section

485 views Asked by At

I'd like to know how to use values from a user input from a custom wizard page. I have a custom page, on which the user types the ODBC connection data. This is the code for this part:

ServerDataPage := CreateInputQueryPage(AskAuthPage.ID,
    'SQL Server Connection Data', '',
    'Please insert data...');
ServerDataPage.Add('ODBC Name:', False);
ServerDataPage.Add('Server Name:', False);
ServerDataPage.Add('User:', False);
ServerDataPage.Add('Password:', False);

This is pretty much working as it should. The page appears with the input boxes and captions.

I also looked up a example from Inno Setup. There's this line:

ExamplePage.Values[0] := GetPreviousData('Name', ExpandConstant('{sysuserinfoname}'));

So I thought there has to be a "backward" thing, such as:

thisIsAVariable := ServerDataPage.Values[x]

Could I use these variables to create an ODBC like this?

Root: HKCU; SubKey: Software\ODBC\ODBC.INI\ODBC Data Sources; ValueType: string; ValueName: Leist; ValueData: SQL Server; Flags: createvalueifdoesntexist uninsdeletevalue
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Driver; ValueType: string; ValueData: {sys}\SQLSRV32.dll
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Server; ValueType: string; ValueData: SERVERADRESS
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Database; ValueType: string; ValueData: DATABASE NAME
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: LastUser; ValueType: string; ValueData: USER
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Password; ValueType: string; ValueData: PASSWORD

And if so, where do I have to put this in the script? The whole "custom wizard pages" thing is in the [Code] section. Are these variables also usable outside this [Code] section?

Greetings

1

There are 1 answers

0
Martin Prikryl On BEST ANSWER

Use a scripted constant to use the values from the custom page in the [Registry] (or any other) section:

[Registry]
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\ODBC Data Sources; \
    ValueType: string; ValueName: Leist; ValueData: SQL Server; \
    Flags: createvalueifdoesntexist uninsdeletevalue
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
    Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Driver; \
    ValueType: string; ValueData: {sys}\SQLSRV32.dll
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
    Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Server; \
    ValueType: string; ValueData: {code:GetServerData|0}
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
    Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Database; \
    ValueType: string; ValueData: {code:GetServerData|1}
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
    Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: LastUser; \
    ValueType: string; ValueData: {code:GetServerData|2}
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
    Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Password; \
    ValueType: string; ValueData: {code:GetServerData|3}
[Code]

var
  ServerDataPage: TInputQueryWizardPage;

function GetServerData(Param: string): string;
begin
  Result := ServerDataPage.Values[StrToInt(Param)];
end;