如何在Inno Setup中使用Pascal变量? [英] How to use a Pascal variable in Inno Setup?

查看:162
本文介绍了如何在Inno Setup中使用Pascal变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[Files]
Source: "C:\MyProg.exe"; DestDir: "{app}"; BeforeInstall: GetHome(); Flags: ignoreversion
[INI]
Filename: "{myVarFromPascal}\.MyProg\settings.ini"; Section: "Settings"; Key: "sound"; String: "1"; Flags: createkeyifdoesntexist
[Code]
procedure GetHome();
     var
  myPascalVar: String;
begin
   RegQueryStringValue(HKEY_CURRENT_USER, 'Volatile Environment','USERPROFILE', myPascalVar);
   MsgBox('Value is "' + myPascalVar + '"', mbInformation, MB_OK);
end;

这是我在INNO设置程序中的三个示例部分.我想在INI节中使用myPascalVar.我该怎么办?

These are my three example sections in INNO Setup. I want to use myPascalVar in the INI Section. How can I do it?

推荐答案

您将需要将变量更改为全局范围,并为所谓的

You will need to change your variable to be in the global scope and write a simple getter function for so called scripted constant:

[Files]
Source: "C:\MyProg.exe"; DestDir: "{app}"; BeforeInstall: GetHome; Flags: ignoreversion

[INI]
Filename: "{code:GetMyVar}\.MyProg\settings.ini"; Section: "Settings"; Key: "sound"; String: "1"; Flags: createkeyifdoesntexist

[Code]
var
  myPascalVar: string;

function GetMyVar(Value: string): string;
begin
  Result := myPascalVar;
end;

procedure GetHome;
begin
  RegQueryStringValue(HKEY_CURRENT_USER, 'Volatile Environment', 'USERPROFILE', myPascalVar);
  MsgBox('Value is "' + myPascalVar + '"', mbInformation, MB_OK);
end;

这篇关于如何在Inno Setup中使用Pascal变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆