<p>Am 08.02.2013 19:52 schrieb "Gerhard Scholz" <<a href="mailto:gs@g--s.de">gs@g--s.de</a>>:<br>
><br>
> Thanks for the help, I understood it now; I also found the test progs.<br>
><br>
> As far I see, it could already be substituted by the following constructs:<br>
><br>
> program RHelper1v ;<br>
><br>
> type<br>
> poLongint = ^ oLongint ;<br>
> oLongint = object<br>
> li : longint ;<br>
> procedure ShowValue ;<br>
> procedure put ( j : longint ) ;<br>
> Function inc : poLongint ;<br>
> end ;<br>
><br>
> procedure oLongInt.showvalue ;<br>
><br>
> begin<br>
> Writeln ( 'Value=', li ) ;<br>
> end ;<br>
><br>
> procedure oLongInt.put ( j : longint ) ;<br>
><br>
> begin<br>
> li := j ;<br>
> end ;<br>
><br>
> function oLongInt.inc : polongint ;<br>
><br>
> begin<br>
> system.inc ( li ) ;<br>
> result := @self ;<br>
> end ;<br>
><br>
> function v ( i : longint ) : polongint ;<br>
><br>
> begin<br>
> result := addr(i) ;<br>
><br>
> end ;<br>
><br>
> var<br>
> i : LongInt ;<br>
><br>
> begin<br>
> i := 3 ;<br>
> olongint(i).showvalue ;<br>
> olongint(i).put ( 4711 ) ;<br>
> olongint(i).showvalue ;<br>
> olongint(i).inc ;<br>
> olongint(i).showvalue ;<br>
> olongint(v(12345678)^).put ( 4711 ) ; // senseless, but possible<br>
> olongint(v(12345678)^).inc ; // senseless, but possible<br>
> olongint(v(12345678)^).showvalue ; // 4712?<br>
> end.<br>
><br>
> And it produces the same assembler code as the construct TYPE HELPER FOR LONGINT<br>
> (which is definitely better readable).</p>
<p>Impressive O.o I would have never thought to use objects like that. The main advantage of helpers compared to your example is that the compiler will do the type checking. </p>
<p>> The same program with type helper:<br>
><br>
> program RHelper1f ;<br>
><br>
> type<br>
> pLongInt = ^ longint ;<br>
><br>
> tLongIntHelper = type helper for LongInt<br>
> procedure ShowValue ;<br>
> procedure put ( j : longint ) ;<br>
> Function inc : pLongint ;<br>
> end ;<br>
><br>
> procedure TLongIntHelper.showvalue ;<br>
><br>
> begin<br>
> Writeln ( 'Value=', self ) ;<br>
> end ;<br>
><br>
> procedure TLongIntHelper.put ( j : longint ) ;<br>
><br>
> begin<br>
> self := j ;<br>
> end ;<br>
><br>
> function tLongInthelper.inc : plongint ;<br>
><br>
> begin<br>
> system.inc ( self ) ;<br>
> result := @self ;<br>
><br>
> end ;<br>
><br>
> var<br>
> i : LongInt ;<br>
><br>
> begin<br>
> i := 3 ;<br>
> i.showvalue ;<br>
> i.put ( 4711 ) ;<br>
> i.showvalue ;<br>
> i.inc ;<br>
> i.showvalue ;<br>
> 12345678.put ( 4711 ) ; // senseless, but possible<br>
> 12345678.inc ; // senseless, but possible<br>
> 12345678.showvalue ; // 4712?<br>
> end.<br>
><br>
> The last 3 lines show that the type helpers allow useless code. I assume such useless code is not catchable by the compiler.</p>
<p>If we could keep track of writes to Self and then mark the methods accordingly we could at least provide a warning or a hint.</p>
<p>And the last line should show 12345678 hopefully :)</p>
<p>Regards,<br>
Sven</p>