Forum > Pas2JS

problem with calling virtual methods?

(1/2) > >>

mr-highball:
pas2js source used is latest trunk pulled 8/22/2020

Trying to implement some classes with pas2js and am noticing an issue with virtual methods. my example is

parent class defined with a virtual method with no implementation

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TNyxElementBaseImpl...//declarationprocedure DoUpdateHeight; virtual; ...//implementationprocedure TNyxElementBaseImpl.DoUpdateHeight;begin  //nothing in baseend 
this parent class, makes a call to the virtual method in this other method,

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TNyxElementBaseImpl.NotifyHeight(const AType: TPropertyUpdateType;  const ASize: INyxSize; const AProperty: TSizeProperty);begin  if AType = puAfterUpdate then    DoUpdateHeight; //  <---------right hereend;  
now, I have a child class which overrides the DoUpdateHeight method here

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TNyxElementBrowserImpl = class(TNyxElementBaseImpl, INyxElementBrowser)...//interfaceprocedure DoUpdateHeight; override;...//implprocedure TNyxElementBrowserImpl.DoUpdateHeight;begin  inherited DoUpdateHeight; // <------- we never get here in the debugger  UpdateSize;end;  
What should be happening is the TNyxElementBrowserImpl.DoUpdateHeight should be used, not the parent's empty stubbed method... but when debugging, the parent method is triggered rather than the overridden child.

Has anyone run into this or spot something that I may be doing improperly?
any help would be appreciated.

for reference, the full source for the examples are found at these lines,
parent:
https://github.com/mr-highball/nyx/blob/master/src/nyx.types.pas#L262
https://github.com/mr-highball/nyx/blob/master/src/nyx.types.pas#L1726

child:
https://github.com/mr-highball/nyx/blob/master/src/nyx.element.browser.pas#L72
https://github.com/mr-highball/nyx/blob/master/src/nyx.element.browser.pas#L149

Ñuño_Martínez:
It shouldn't be, but did you tried to add SELF. to the calls?  Maybe the transpiler is forgetting to add this. to it and it may mess up the thing (never used pas2js though).

BTW, this is to push up this message so more people read it. ;)

mr-highball:
thanks for replying (and for the "bump") @Ñuño_Martínez, I hadn't thought of trying that, but making the change to Self.DoUpdateHeight still seems to be calling the parent stub method rather than the overridden one

mr-highball:
I created this issue in mantis with a test scenario project... but tbh I couldn't break it in the same way that I'm seeing, and have no idea what to try next, just posting this for transparency (and the chance someone spots something I'm not)
https://bugs.freepascal.org/view.php?id=37633

Ñuño_Martínez:
Are you sure you're creating the object with the correct class?  That question seems silly but it is a quite common mistake (I did it no long ago :-[).

Navigation

[0] Message Index

[#] Next page

Go to full version