user1552003
user1552003

Reputation: 61

how to pass parameter into Files section in Inno

I've googled a lot but do not find the answer on my question.

How to correctly pass a parameter to function like this: getPath('myParam')?

I have such code:

[Files]
Source: "AppName\*"; DestDir: "{code:getPath('myParam')}";

[Code]
function getPath(Param: String):String;
  var  objRegExp: String;
      path: Variant;
begin
  path := ExpandConstant('{userappdata}') +'\Adobe\' + Param + '\.+';
  objRegExp := CreateOleObject('VBScript.RegExp');
  objRegExp.Pattern := '(.+(\\Version )?( CS)?\d.+)';
   if objRegExp.Test(path) then
      begin
         objRegExpMatches := objRegExp.Execute(path);
         Result := objRegExpMatches.Item[0].Value;
      end;
end

Upvotes: 3

Views: 1301

Answers (1)

TLama
TLama

Reputation: 76693

As it's shown in the reference, the prototype of the scripted constants looks like this:

{code:FunctionName|Param}

So you need to add the | char after the function name and remove parentheses with the single quote marks from your scripted constant function call. In pseudo-code it might look like this:

[Files]
Source: "AppName\*"; DestDir: "{code:GetPath|Your input string value}";

[Code]
function GetPath(Param: string): string;
begin
  MsgBox(Param, mbInformation, MB_OK);
end;

Upvotes: 3

Related Questions