Jump to content
Wak

Generic pointer type to a generic type

Recommended Posts

I've worked with generics quite a bit, but I have never tried to define a generic pointer type to another generic type:

  TMyType<T> = record
    ID: T;
  end;

  PMyType<T> = ^TMyType<T>;            // Error: E2508 type parameters not allowed on this type
  TMyTypes<T> = array of TMyType<T>;   // OK
  PMyTypes<T> = array of ^TMyType<T>;  // OK

  TMyTypeHack<T> = record
    P: ^TMyType<T>;                    // OK
  end;

This raises a compiler error. It seems Delphi doesn't allow type aliases like this, but allows using them in the definition of array/record types. Has anyone found a trick to achieve it? Thanks!

Share this post


Link to post

I feel like I seen this somewhere .. maybe even from Marco Cantu .. mentioning that this "hack" was necessary.

 

 PMyType<T> = record
    P: ^TMyType<T>;                   
 end;

 

Share this post


Link to post

Thanks! That matches my previous record definition. With operator overloading, it might be usable, though it could still lead to some confusion during use."

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×