7

When I use the INNO wizard I get an *.iss file that contains in its setup section:

[Setup]
AppId={87E1AD40-F32B-4EF7-A2FF-5B508814068A}

<statements not included here}

I then add a procedure in the code section for the generation of an *.ini file to be used as input to my application. The code section contains the following:

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
 // Purpose: write an *.ini file
 //    Used as input to the program to be executed
 var
   S: string;
 begin
   if CurStep = ssPostInstall then
   begin
     //* Output language entered
     S := Format('[%s]'+#13#10, ['LANGUAGE']);
     SaveStringToFile(ExpandConstant('{app}\UserInputs.ini'), S, False);
     S := Format('language = %s'+#13#10, [ActiveLanguage]);
     SaveStringToFile(ExpandConstant('{app}\UserInputs.ini'), S, True);      

     <code not included here>

     //* Output AppId code generated by INNO
     S := Format('[%s]'+#13#10, ['REGISTRATION']);  // key word
     SaveStringToFile(ExpandConstant('{app}\UserInputs.ini'), S, True);
     // S := Format(??)
     //SaveStringToFile(ExpandConstant('{app}\UserInputs.ini'), S, True);
  end;
end;

How can I Format AppId so that S will contain "87E1AD40-F32B-4EF7-A2FF-5B508814068A" [i.e., S := Format(??)]?

1 Answer 1

7

If you want to expand certain [Setup] section setting in your code, you can use the SetupSetting preprocessor function. In your question you've mentioned you want to get the AppId directive value, which you've set to a GUID value including {} chars, which you want to have stripped on your output. The following script shows how to get the AppId directive value and how to copy just the part without those enclosing {} chars:

[Setup]
AppId={{87E1AD40-F32B-4EF7-A2FF-5B508814068A}
AppName=My Program
AppVersion=1.5
DefaultDirName=My Program

[Code]
procedure InitializeWizard;
var
  S: string;
begin
  S := '{#SetupSetting("AppId")}';
  S := Copy(S, 3, Length(S) - 3);
  MsgBox(S, mbInformation, MB_OK);
end;
7
  • 1
    Excellent TLama --- you are clearly an expert on INNO-setup. I am impressed and very appreciative. I noticed that your answer even compensated for my error (I had shown AppId={87E1AD40-F32B-4EF7-A2FF-5B508814068A}). As you can also see I have decided to use an *.ini file (rather than a normal *.txt file). Thanks again @TLama :-)
    – Birdy40
    Nov 16, 2013 at 18:03
  • 1
    You're welcome! ;-) P.S. I always test the code I'm posting (if I don't explicitly say it's untested).
    – TLama
    Nov 16, 2013 at 18:09
  • Oh, and about the INI files. There's a separate [INI] section. Or for a [Code] section, there's a set of functions to use with INI files, see "INI File functions" chapter on this help page. So Inno Setup offers you a sufficient support for reading and writing to INI files, so you don't need to build them by yourself.
    – TLama
    Nov 16, 2013 at 18:38
  • Ok @TLama, your last comment on the use of [INI] withing INNO interests me. I looked at the help link you provided; but, it wasn't clear to me how one defines an *.ini file and how to write key-word sections with entry values. More specifically, the replacement of my code approach in the [Code] section by it's equivalent in an [INI] section is not at all obvious to me.
    – Birdy40
    Nov 17, 2013 at 10:12
  • 1
    True, although I think it's a little messier that way. (Mostly because it's less generic -- the snippet I posted will work regardless of the actual AppId, but once you start messing with Copy etc it will work only if the id has the braced-guid form.) But it's true that might be more applicable to what the OP wants. I just wanted to suggest the other way first in case they didn't really mind whether the braces were present or not, because it's easier to leave them in.
    – Miral
    Nov 19, 2013 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.