type
TRecWithMetods = object
FValue: Integer;
procedure Foo;
end;
Behaves exactly like a record. You do *NOT* need to care about freeing any memory. You do neither need to create it, nor destroy it.
And what does "but only within the scope of one procedure" mean?
The above can be used as a function result or var-parameter too.
It can be a field in a class, or in *another* object.
Of course like a record, they can not be circular. A record can not contain a field of it's own type. neither can an "object".
Note that a danger of using TP objects instead of records with methods is that TP objects are not safe with automated types (ansistrings, dynamic arrays). So I wouldn't recommend this.
Is that limitation documented? Never knew about it.