Create shortcut based on result of Pascal function

248 views Asked by At

I'm trying to create a shortcut based on the result of a Pascal function (which returns a path), but can't how to do it.

This is what I'm trying to do:

[Icons]
Name: '{userstartup}\Myprog'; Filename: MyFunctionThatReturnsPath() + 'Myprog.exe';

But the function is never called, instead the filename is treated as a simple string.

1

There are 1 answers

1
Martin Prikryl On BEST ANSWER

The [Icons] section entry should look like:

[Icons]
Name: "{userdesktop}\Myprog"; Filename: "{code:MyFunctionThatReturnsPath}\Myprog.exe"

And the corresponding function is:

[Code]

function MyFunctionThatReturnsPath(Param: string): string;
begin
   Result := 'C:\path';
end; 

The function must take a string argument, even if you do not actually make use of it. See Pascal Scripting: Scripted Constants:

The called function must have 1 String parameter named Param, and must return a String or a Boolean value depending on where the constant is used.