With methods-always-virtual, if a method, GetObj, returns an object, and you call a method directly from the call to GetObj, gpc fails with an error.
Ie, obj.GetObj.Method( whatever ) fails.
Using a temporary variable works fine, ie:
obj2 := obj.GetObj; obj2.Method( whatever )
compiles without problems.
Test program and error output below.
Thanks, Peter.
% gp peterV.pas /peterV.pas:7: warning: object type has virtual method, but no constructor /peterV.pas:11: warning: object type has virtual method, but no constructor /peterV.pas: In main program: /peterV.pas:30: error: request for field `Doit' in something not /peterV.pas:30: error: a record, schema or object
{$methods-always-virtual} program peterV;
type ObjectA = object procedure Doit; end; ObjectB = object obj: ObjectA; function GetA: ObjectA; end;
procedure ObjectA.Doit; begin WriteLn( 'OK' ); end;
function ObjectB.GetA: ObjectA; begin return obj; end;
var a: ObjectA; b: ObjectB; begin New(a); New(b); b.obj := a; b.GetA.Doit; end.