Search code examples
inno-setuppascalscript

Concatenating string and integer fails with "Type mismatch" error


I have the following Inno Setup script, and I'm getting this error on the SaveStringToFile line:

Type Mismatch

Can anybody spot my mistake?

Thank you!

var
  ErrorCode: Integer;
begin
  ShellExec(
    'open', 'taskkill.exe', '/f /im procterm.exe', '', SW_HIDE,
    ewWaitUntilTerminated, ErrorCode);

  SaveStringToFile(
    'c:\program data\myapp\innolog.txt',
    'Error code for procterm was: ' + ErrorCode, True);
end;

Solution

  • The problem is that you are trying to "sum" a string with a number (an integer):

    'Error code for procterm was: ' + ErrorCode
    

    That's not possible in Pascal/Pascal Script.

    You have to convert the number/integer to a string with the IntToStr function:

    'Error code for procterm was: ' + IntToStr(ErrorCode)
    

    Or use the Format function like:

    Format('Error code for procterm was: %d', [ErrorCode])