Many thanks for all your explanations.
The penny really dropped with the suggestion to use variants.
The When is a look-alike of the inline 'if' that we know in C
( r= condition ? trueValue : falseValue )
and I always wondered whether there is a simpler approach than using overloads for each possible type. The answer is: Variants.
So I replaced all my When's by
function When(Wahr:Boolean; TrueValue, FalseValue: variant): variant; overload;
begin
if wahr then
Result := TrueValue
else
result := FalseValue;
end;
However this still caused compilation errors for Char and RawByteString.
So I added 2 overloads for these types.
And now it compiles/runs fine on Lazarus, Delphi-5 and Delphi-Seattle.
When doing this test:
s:= when(true, 'yes', 'no');
Lazarus calls the RawByteString version.
Delphi-Seattle calls the Variant version
Delphi-5 calls the Variant version (it does not have RawByteString)