2
uses
  Generics.Collections, types, rtti, System.Generics.Collections;

procedure GimmePairArray(const APairArray: TArray<TPair<string, TValue>>);
begin

end;

procedure TForm2.FormCreate(Sender: TObject);
var
  _PairArray: TArray<TPair<string, TValue>>;
begin
  _PairArray := TArray <TPair<string, TValue>>.Create(TPair<'"reset changes"', TValue.From<Boolean>(True)>);
  GimmePairArray(_PairArray);
end;

Results in compiler error: [DCC Error] Unit2.pas(38): E2003 Undeclared identifier: 'TPair' What I am doing wrong? TPair is declared in System.Generics.Collections and I have it in my Uses.

0

1 Answer 1

7

First of all, the compiler says that TPair does not exist. In spite of your belief otherwise the compiler is correct. TPair<K, V> exists, but not TPair.

The compiler does point you to the problem. It would have been helpful had you indicated the line of the program that failed to compile, but it is clear enough that this code is the problem:

TPair<'"reset changes"', TValue.From<Boolean>(True)>

This is a syntax error. You mean:

TPair<string, TValue>.Create('"reset changes"', TValue.From<Boolean>(True))

The compiler looks at your code and tries to decide whether the < is part of a generic type expression. Because the expression to the right of < is not a type it concludes that is let is not and that your < is the less than comparison operator. And of course it then says that TPair does not exist. It doesn't, as explained at the top.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.