# Type Mismatch when calling a function

**URL:** https://talk.remobjects.com/t/type-mismatch-when-calling-a-function/24713
**Category:** Pascal Script
**Created:** [May 7, 2021, 5:49am UTC](https://talk.remobjects.com/t/type-mismatch-when-calling-a-function/24713 "2021-05-07T05:49:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sebastian1](https://talk.remobjects.com/user_avatar/talk.remobjects.com/sebastian1/32/15640_2.png) [@sebastian1](https://talk.remobjects.com/u/sebastian1)
#### Post date: [May 7, 2021, 5:49am UTC](https://talk.remobjects.com/t/type-mismatch-when-calling-a-function/24713/1 "2021-05-07T05:49:12Z")

</div>

Hello,

I am currently writing Pascal Script code for usage in Inno Setup.  
Inno provides a function called `FmtMessage` to format a string. It is defined as  
`function FmtMessage(const S: String; const Args: array of String): String;`, see also [Inno Setup Help (jrsoftware.org)](https://jrsoftware.org/ishelp/index.php?topic=isxfunc_fmtmessage).

Now I have an issue calling this method.

When I call it normally like that:  
`FmtMessage('Some %1 test %2 string %3', [IntToStr(100), 'Somevalue', IntToStr(5)]);` it works.

However I wanted to wrap that method in a helper function, because the first string comes from the translation system, and pass the arguments (that Array of String) through that method. When I do that, I get a Type Mismatch runtime error:

```auto
function FormatCustomMessage(const messageId: String; const arguments: Array of String): String;
begin
	result := FmtMessage(CustomMessage(messageId), arguments);
end;

```

I wasn’t sure why that was, but I figured out that the problem is the arguments part.  
When I prepare the arguments differently, I also get the Type Mismatch runtime error:

```auto
function FormatCustomMessage(): String;
var
	message: String;
	args: Array of String;
begin
	message := 'Some %1 test %2 string %3';
	args := [IntToStr(100), 'Caption', IntToStr(100)];

	result := FmtMessage(message, args); // Type Mismatch error
end;

```

So the only difference here is, that I assign the Array to a variable and pass that, instead of writing it directly into the `FmtMessage` call. And that results in a Type Mismatch error, and I don’t understand why.

I also already tried this:

```auto
function FormatCustomMessage(): String;
var
	message: String;
	args: Array of String;
begin
	message := 'Some %1 test %2 string %3';

	SetArrayLength(args, 3);
	args[0] := IntToStr(100);
	args[1] := 'Caption';
	args[2] := IntToStr(5);

	result := FmtMessage(message, args); // Type Mismatch error
end;

```

Same thing. If I write the `['param1', 'param2']` array in the call directly it works, when passing it from a variable with the same type, it doesn’t.

I didn’t really touch pascal for the last 20 years or so, however I have a Delphi background, and not being capable of passing an Array of String through one function to the next makes me feel a bit dumb.

Am I doing something wrong here, or is that a problem with Pascal Script?  
I mean, I don’t really _need_ that helper function, as its an installer script and I can put the nested call to FmtMessage() with CustomText() everywhere, but I really like to know what I did wrong here, if that’s the case.

Thanks,

Sebastian
