0

I have the following code that doesn't compile, and I can't find an explanation as to why.

TIndexArray<TType> = array of TType;

TIndexList<TArrayType; TType: TIndexArray<TArrayType>> = class
end;

It says the

Type 'TIndexArray' is not a valid constraint.

But if TIndexArray is a class and not an array type it works.

1
  • You don't really need TType in your class declaration. You can just use TIndexArray<TArrayType> directly in your class, or declare TType = TIndexArray<TArrayType> within the class. Commented Dec 22, 2022 at 10:17

1 Answer 1

3

Array types are not supported as constraints. This is documented behavior:

https://docwiki.embarcadero.com/RADStudio/en/Constraints_in_Generics

Constraint items include:

  • Zero, one, or multiple interface types

  • Zero or one class type

  • The reserved word "constructor", "class", or "record"

No mention of array types.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.