Open GoogleCodeExporter opened 9 years ago
Interestingly the above code ends up in an infinite loop and a stack overflow
in Delphi... is there a syntax to access the original method in Delphi in such
a case? or is it hidden forever?
Currently helpers have lower priorities than "native" methods, in part because
I didn't knew how to resolve the above ambiguity (didn't find anything in the
doc about it).
Original comment by zar...@gmail.com
on 30 Apr 2012 at 3:42
Delphi solution:
TObjectHelper = Class Helper For TObject
Class Function ClassName : String;
End;
Class Function TObjectHelper.ClassName : String;
Begin
Result := 'Helper.' + Inherited ClassName;
End;
Original comment by kazantse...@mail.ru
on 30 Apr 2012 at 3:54
This issue was closed by revision r1431.
Original comment by zar...@gmail.com
on 2 May 2012 at 2:43
Code:
Type
THelper1 = Helper For TObject
Class Function ClassName : String;
Begin
Result := 'Helper1.' + ClassName;
End;
End;
Type
THelper2 = Helper For TObject
Class Function ClassName : String;
Begin
Result := 'Helper2.' + ClassName;
End;
End;
PrintLn(TObject.Create.ClassName);
Output:
Helper1.TObject
Original comment by kazantse...@mail.ru
on 3 May 2012 at 9:06
The last snippet is about the scope & priority resolution.
If both helpers are for the same type, I would say to prioritize the last one.
But if they're for different types but both apply, what to do?
f.i Helper2 is on TObject, Helper1 on TSubObject, and you're calling them on a
TSubObject, should Helper2 still have more priority (because it was declared
last) or less priority (because it is less specific)?
Original comment by zar...@gmail.com
on 3 May 2012 at 10:08
I think, helper specialization has more priority than declaration order
Original comment by kazantse...@mail.ru
on 3 May 2012 at 10:46
Re-opened the issue so as not to forget about it.
Original comment by zar...@gmail.com
on 3 May 2012 at 2:54
Note that consecutive helpers for same class are ignored in Delphi based on order of "use" in client code (having reached Delphi11 version now), unless you use class helper inheritance, aka Helper2 = helper class(SomeOtherHelper) for TSameObject
Original issue reported on code.google.com by
kazantse...@mail.ru
on 30 Apr 2012 at 3:18