How can I make the Dictionary in the following code to accept both TC and TC1?
How can I make the Dictionary in the following code to accept both TC and TC1?
type
TC = class
end;
TC1 = class (TC)
end;
TR= class of TC;
var
dict: TDictionary;
ref: TR;
c: TC;
c1: TC1;
begin
dict:=TDictionary.Create;
/////The following 4 lines generate an error
c:=ref.Create;
dict.Add(1, c);
c1:=ref.Create;
dict.Add(2, c1);
///////////////////
dict.Free;
end.
TIA
type
TC = class
end;
TC1 = class (TC)
end;
TR= class of TC;
var
dict: TDictionary
ref: TR;
c: TC;
c1: TC1;
begin
dict:=TDictionary
/////The following 4 lines generate an error
c:=ref.Create;
dict.Add(1, c);
c1:=ref.Create;
dict.Add(2, c1);
///////////////////
dict.Free;
end.
TIA
c and c1 are object references, your dictionary only accepts class references. define dict as TDictionary
ReplyDeletealso, you can't use "ref" (which is a class reference to TC) to create an instance of TC1.
Oh yes, of course. Thanks
ReplyDelete