Generic TypeIdenitifier convertion.How?

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-18T10:56:38Z Indexed on 2010/04/18 11:03 UTC
Read the original article Hit count: 222

How do I convert the TypeIdenitifier to a class type? I need to use implicit convertion.

type
  TMyChildArray<T>=class(TMyArray<T>)
    private
      FData:Array of T;
      procedure AddEnd();
  end;

  TTypeIdenitifierParentClass=class(TAnotherParentClass)
    protected
      TestField:Cardinal;
  end;


  procedure TMyChildArray<T>.AddEnd();
  var elem:T;
  begin
    for elem in Fdata do
      TTypeIdenitifierParentClass(elem).TestField:=0;
  end;

I get "Invalid typecast" on the implicit convertion "TTypeIdenitifierParentClass(elem).TestField:=0;".

The principle I want to use is that the TypeIdenitifier will represent a class that descends from TTypeIdenitifierParentClass.There are many class types,but all of them descend that class.

How do I do this?

© Stack Overflow or respective owner

Related posts about generics

Related posts about delphi