Yes, I was not clear. I meant to explain that the following is illegal in mode TP or TP itself:
{%FAIL%}
{$ifdef fpc}{$mode tp}{$endif}
{ pure TP }
type
TMyObject = object; // try forward
TmyObject2 = object
obj:TMyObject; // try use it
end;
TMyObject = object // try implementation of forward
end;
begin
end.
As explained, TP has no concept of class. Adding {$modeswitch class} mutilates the intend.
And this is legal code:
{$ifdef fpc}{$mode objfpc}{$endif}
type
TMyObject = class;
TmyObject2 = class
obj:TMyObject;
end;
TMyObject = class
end;
begin
end.
Just because of the mode and class concept.
I might add that Harmut's code should work if the modeswitch is in the right place, since this compiles:
{$ifdef fpc}{$mode tp}{$modeswitch class}{$endif}
type
TMyObject = class;
TmyObject2 = class
obj:TMyObject;
end;
TMyObject = class
end;
begin
end.
If it is sane, though, I have no opinion, since I also sometimes create bastard modes.
Modeswitches must be added AFTER choosing the default mode, otherwise they get reset.
Since his snippet has the right order I am a bit bemused Hartmut did not get it to work.