Syntactic Fructose Syntactic Fructose - 29 days ago 18
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;
var
I: Integer;
begin
Result := '';
for I := 0 to GetArrayLength(SerialEdits) - 1 do
Result := Result + SerialEdits[I].Text + ADelimiter;
if GetArrayLength(SerialEdits) > 1 then
begin
Delete(Result, Length(Result), 1);
end
end;


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

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.