Sign in Join

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

Mailing lists / fpc-pascal / 2017-02

Typecast class-of to class

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Mattias Gaertner

Hi,

FPC allows to type cast a class-of variable to a class instance. Is this a bug or a feature?

var
  c: TClass;
begin
  TObject(c).ClassName; // crash
end.

Mattias

Marco van de Voort
to Mattias Gaertner

In our previous episode, Mattias Gaertner said:

Show quoted text 9 lines
FPC allows to type cast a class-of variable to a class instance. Is this a bug or a feature? var c: TClass; begin TObject(c).ClassName; // crash end.

Feature (allowed because equal in size), used in e.g. Registerxxx functions to add class references to the .objects part of tstringlist. Delphi has no container type for references