[Pas2js] My 1st type helper
Mattias Gaertner
nc-gaertnma at netcologne.de
Sat Mar 2 20:09:51 CET 2019
On Sat, 2 Mar 2019 09:06:12 -0700 (MST)
warleyalex via Pas2js <pas2js at lists.freepascal.org> wrote:
> I think there's an issue: "class helper takes precedence over the
> actual class type", for instance:
> ----------------------------------
> type
> TMyClass = class
> procedure MyProc;
> function MyFunc: Integer;
> end;
>
> type
> TMyClassHelper = class helper for TMyClass
> procedure HelloWorld;
> function MyFunc: Integer;
> end;
>
> implementation
>
> procedure TMyClass.MyProc;
> var
> X: Integer;
> begin
> X := MyFunc;
> end;
>
> function TMyClass.MyFunc: Integer;
> begin
> WriteLn('TMyClass.MyFunc called');
> end;
>
> procedure TMyClassHelper.HelloWorld;
> begin
> Writeln(Self.ClassName); // Self refers to TMyClass type, not
> TMyClassHelper
> end;
>
> function TMyClassHelper.MyFunc: Integer;
> begin
> WriteLn('TMyClassHelper.MyFunc called');
> end;
>
> (...)
>
> var
> X: TMyClass;
> begin
> X := TMyClass.Create;
> X.MyProc; // Calls TMyClass.MyProc
> // X.HelloWorld; // Calls TMyClassHelper.HelloWorld
> X.MyFunc; // Calls TMyClassHelper.MyFunc
> ----------------------------------
> should output this:
> (*
> TMyClass.MyFunc called
No, helpers are active even inside the helped class itself.
> TMyClass
> TMyClassHelper.MyFunc called
> *)
>
> but it shows
>
> (*
> TMyClass.MyFunc called
>
> TMyClass.MyFunc called
> *)
fpc gives:
TMyClassHelper.MyFunc called
TMyClass
TMyClassHelper.MyFunc called
pas2js 1.40RC3 gives the same:
TMyClassHelper.MyFunc called
TMyClass
TMyClassHelper.MyFunc called
> Note:
> ===
> a) I have commeted the line "X.HelloWorld;" because I really didn't
> test it, I'm using the non-fixed-pas2js.
Which pas2js is that?
> When we call
> TMyClassHelper.HelloWorld, I believe the "Self" refers to TMyClass
> type, not TMyClassHelper, the console should display "TMyClass",
Yes, and it does here.
>[...]
Mattias
More information about the Pas2js
mailing list