Either {$mode delphi} or {$mode objfpc} will solve the issue.
Other modes, like {$mode tp} or {$mode fpc}, the default, will trigger it. That's because in these modes the objpas unit is not loaded. That is documented.
It is a bit strange, since the objfpc unit pulls in classes, but old school objects do not need it, provided constructor /destructor are named init/done.