Sign in Join

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

Mailing lists / fpc-devel / 2026-11

Another "bug or feature" type alias

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Martin Frb

Variables of non-related classes can't be assigned to each other. E.g. wrong:
   f := b

type = type ...
creates a new type.
   TRec2 = type TRec;
then "r := r2" will not be allowed.

Do the same for classes.
  TFoo2 = type TFoo;
and
  f:= f2;
is not forbidden?

program Project1;
{$Mode objfpc}
type
   TRec = record a: integer; end;
   TRec2 = type TRec;
   TFoo = class a: integer; end;
   TFoo2 = type TFoo;
   TBar = class a: integer; end;
var
   r: TRec;
   r2: TRec2;
   f: TFoo;
   f2: TFoo2;
   b: TBar;
begin
   //r := r2;
   //f := b;
   f := f2;
   //(f as TBar).a := 1;
   (f as TFoo2).a := 1;
end.

Reply by email

Ondrej Pokorny
to Martin Frb
Martin Frb wrote
f := f2;

Delphi doesn't allow that:
[dcc32 Error] Project1.dpr(23): E2010 Incompatible types: 'TFoo' and 'TFoo2'

Honestly, I haven't known the "type" keyword can be used for classes.

Ondrej

Reply by email