Syntactic Fructose Syntactic Fructose - 1 year ago 226
Pascal Question

Inno Setup type mismatch when assigning function return value to a string

I have the following function in my Inno setup:

function GetSerialNumber(ADelimiter: Char): string;
I: Integer;
Result := '';
for I := 0 to GetArrayLength(SerialEdits) - 1 do
Result := Result + SerialEdits[I].Text + ADelimiter;
if GetArrayLength(SerialEdits) > 1 then
Delete(Result, Length(Result), 1);

Within another function below, I have a variable named
Serial: string
, but when I do

Serial := GetSerialNumber('');

I get a type mismatch error, does anyone know what I'm doing wrong? Thanks!

Answer Source

The problem is not the return value, but the argument.

The '' is not a valid char literal. A char literal must be exactly one character long. The '' is a string.

If you want to allow an empty delimiter, change the argument type to the string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download