<div dir="ltr"><div dir="ltr">On Fri, May 10, 2019 at 4:57 PM Sven Barth via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello together!<br>
<br>
We are pleased to announce that Free Pascal now supports the usage of <br>
multiple active helper types per extended type. This feature has been <br>
developed by Ryan Joseph, so thank you very much Ryan.<br></blockquote><div><br></div><div>awesome news.</div><div><br></div><div>thanks for implementing it dudes, i'm going to update my git to test it!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
To enable this feature you need to use the new modeswitch multihelpers. <br>
This will then result in the following code to compile:<br>
<br>
=== code begin ===<br>
<br>
{$mode objfpc}<br>
{$modeswitch typehelpers}<br>
{$modeswitch multihelpers}<br>
<br>
type<br>
TObjectHelper1 = type helper for TObject<br>
procedure Foo;<br>
procedure Foobar;<br>
end;<br>
<br>
TObjectHelper2 = type helper for TObject<br>
procedure Bar;<br>
procedure Foobar;<br>
end;<br>
<br>
procedure TObjectHelper1.Foo;<br>
begin<br>
Writeln('Foo');<br>
end;<br>
<br>
procedure TObjectHelper1.Foobar;<br>
begin<br>
Writeln('Foobar1');<br>
end;<br>
<br>
procedure TObjectHelper2.Bar;<br>
begin<br>
Writeln('Bar');<br>
end;<br>
<br>
procedure TObjectHelper2.Foobar;<br>
begin<br>
Writeln('Foobar2');<br>
end;<br>
<br>
var<br>
o: TObject;<br>
begin<br>
o.Foo;<br>
o.Bar;<br>
o.Foobar; // this will call TObjectHelper2.Foobar<br>
end.<br>
<br>
=== code end ===<br>
<br>
As can be seen in the example above if a member is present in multiple <br>
helpers then it will be resolved by the usual scoping rules. More common <br>
is however is to have helpers in different units:<br>
<br>
=== code begin ===<br>
<br>
unit test1;<br>
<br>
{$mode objfpc}<br>
{$modeswitch typehelpers}<br>
<br>
interface<br>
<br>
type<br>
TObjectHelper1 = type helper for TObject<br>
function Func: LongInt;<br>
end;<br>
<br>
implementation<br>
<br>
function TObjectHelper1.Func: LongInt;<br>
begin<br>
Result := 1;<br>
end;<br>
<br>
end.<br>
<br>
unit test2;<br>
<br>
{$mode objfpc}<br>
{$modeswitch typehelpers}<br>
<br>
interface<br>
<br>
type<br>
TObjectHelper2 = type helper for TObject<br>
function Func: LongInt;<br>
end;<br>
<br>
implementation<br>
<br>
function TObjectHelper2.Func: LongInt;<br>
begin<br>
Result := 2;<br>
end;<br>
<br>
end.<br>
<br>
program testA;<br>
<br>
uses<br>
test1, test2;<br>
<br>
var<br>
o: TObject;<br>
begin<br>
Writeln(o.Func); // will print 2<br>
end.<br>
<br>
program testB;<br>
<br>
uses<br>
test2, test1;<br>
<br>
var<br>
o: TObject;<br>
begin<br>
Writeln(o.Func); // will print 1<br>
end.<br>
<br>
=== code end ===<br>
<br>
Sidenote: yes, modeswitch typehelpers also allows "type helper" to be <br>
used with classes and records.<br>
<br>
Regards,<br>
Sven</blockquote><div> </div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Silvio Clécio</div></div></div></div>