[Pas2js] My 1st type helper
warleyalex
warleyalex at yahoo.com.br
Sat Mar 2 17:06:12 CET 2019
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
TMyClass
TMyClassHelper.MyFunc called
*)
but it shows
(*
TMyClass.MyFunc called
TMyClass.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. When we call TMyClassHelper.HelloWorld, I
believe the "Self" refers to TMyClass type, not TMyClassHelper, the console
should display "TMyClass", anyway I couldn't test if will return "TMyClass".
b) I think there's an issue here. Note that the class helper function MyFunc
should be called, because the class helper takes precedence over the actual
class type.
the compile should emits something like this:
===================================
rtl.createHelper($mod,"TMyClassHelper",null,function () {
this.MyFunc = function () {
console.log("TMyClassHelper.MyFunc called");
};
});
$mod.X = pas.Unit3.TMyClass.$create("Create");
$mod.X.MyProc();
//$mod.X.MyFunc();
console.log( pas.Unit3.TMyClassHelper.MyFunc() );
===================================
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list