Note that this is not a duplicate of Pointer to generic type. It's a followup question.
I know it is possible to define a pointer to any generic type.
It just that Delphi makes it complicated. It was meant to be impossible, but due to a compiler bug the option slipped through.
This is what the linked question answers.
My question is:
How do I define a pointer to a generic record without encapsulating it in a surrounding class?
Example code:
TGenericRecord<T> = record
Data: integer;
Procedure SomeMethod; inline; <<<< inlining is vital here.
end;
I want to get a type safe pointer to TGenericRecord.
I do not want to wrap the record in a surrounding class because in my experiments I've found that that disables the inlining.
How do I get a typesafe generic pointer to this record.
Use case
{class} function create(size: integer): PGenericRecord{<T>}
I want to be able to create records on the heap in addition to the stack.
Type PT = ^T;inside the record and use it asvar m: TMiniStack<Integer>.PT;withm := TMiniStack<Integer>.Create;.^TMiniStack<T>.