Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-11

Type used to specialize a generic

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joao Morais

Hello list, is there a safe way to know the PTypeInfo, or at least the string literal of the type(s) used to specialize a generic? Eg:

TBarList = specialize TGenericList<TBar>

On the sample above, starting with PTypeInfo of TBarList I know it was specialized using TBar type. I was using the following hack on 2.6.x:

     VPos := Pos('$', AClassName);
     if VPos > 0 then
       VTypeName := Copy(AClassName, VPos + 1, Length(AClassName));

...which is broken on 2.7.

Joao Morais

Reply by email

Sven Barth
to Joao Morais
"Joao Morais" wrote
Hello list, is there a safe way to know the PTypeInfo, or at least the

string literal of the type(s) used to specialize a generic?

No, you can't.
There might be something for this in the future, because I'll need something like that myself, but it will be quite some time till then.

Regards,
Sven

Reply by email

Joao Morais
to Sven Barth
Sven Barth wrote 12 lines
Am 23.11.2014 18:11 schrieb "Joao Morais" < >: > > > Hello list, is there a safe way to know the PTypeInfo, or at least the string literal of the type(s) used to specialize a generic? No, you can't. There might be something for this in the future, because I'll need something like that myself, but it will be quite some time till then.

Hello Sven, thanks for clarifying this. Saying "quite some time" you mean post 2.8? So what about an unsafe way on 2.8? =) A PTypeInfo would be *very* nice, but a string anywhere with the type name will also help a lot, just like 2.6.x does. Without this trick I cannot use my metadata framework with 2.8 :(

Reply by email

Sven Barth
to Joao Morais
Joao Morais wrote 16 lines
Em 23/11/14 15:49, Sven Barth escreveu: > > Am 23.11.2014 18:11 schrieb "Joao Morais" < > >: > > > > > > Hello list, is there a safe way to know the PTypeInfo, or at least > the string literal of the type(s) used to specialize a generic? > > No, you can't. > There might be something for this in the future, because I'll need > something like that myself, but it will be quite some time till then. > Hello Sven, thanks for clarifying this. Saying "quite some time" you mean post 2.8?

Definitely post 2.8.

So what about an unsafe way on 2.8? =) A PTypeInfo would be *very* nice, but a string anywhere with the type name will also help a lot, just like 2.6.x does. Without this trick I cannot use my metadata framework with 2.8 :(

There is no way. It's dangerous to rely on the name mangling and this needed to be changed, because otherwise type names would have gotten to long.

Regards,
Sven

Reply by email

silvioprog
Joao Morais wrote 13 lines
Hello list, is there a safe way to know the PTypeInfo, or at least the string literal of the type(s) used to specialize a generic? Eg: TBarList = specialize TGenericList<TBar> On the sample above, starting with PTypeInfo of TBarList I know it was specialized using TBar type. I was using the following hack on 2.6.x: VPos := Pos('$', AClassName); if VPos > 0 then VTypeName := Copy(AClassName, VPos + 1, Length(AClassName)); ...which is broken on 2.7.

Unfortunatelly, no.

In Delphi, you can:

  TBar = class(TObject)
  end;
  TBarList = class(TList<TBar>)
  end;
  WriteLn(TBarList.ClassParent.ClassName);

Result: TList<Unit1.TBar> // so you can get the unit/type used between ""

But currently in FPC (tested from trunk):

{$mode delphi}
  TBar = class(TObject)
  end;
  TBarList = class(TFPGList<TBar>)
  end;
WriteLn(TBarList.ClassParent.ClassName);

Result: TFPGList$1$crc07FFF574

Silvio Clécio My public projects - github.com/silvioprog

Reply by email