Oberon Community Platform Forum
November 24, 2017, 04:50:46 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Override and Super call  (Read 2095 times)
danp
Newbie
*
Posts: 37


« on: August 11, 2008, 02:06:17 PM »

Hello,

I have two questions:

1. How to call an ancestor's overridden method? Ex:
Code:
definition A;
var {public} i : integer;
procedure P;
end A.

implementation A;
procedure P;
begin
i := 5
end P;
end A.

object O implements A;
var {public} v : integer;

procedure {public} P implements A.P;
begin
A.P;  (* here I call the implementation's P *)
v := 2;
end P;
end O.



module Test;
import O;
var
o : O;
begin
o.P;
writeln("i = ", o.i:0, "  v = ", o.v:0);
readln
end Test. 

The A.P call is accepted by the compiler, but it does nothing at run time. The result is:
  i = 0  v = 2
What could be the correct call in this case? Something like Activ Oberon's super P^ call.
To make it works I have to rename A.P as A.Pi, but is another thing:

Code:
definition A;
var {public} i : integer;
procedure Pi;
procedure P;
procedure P2;
end A.


implementation A;
procedure Pi;
begin
i := 5;
self.P2
end Pi;

procedure P2;
begin
writeln("I am A.P2");
end P2;
end A.

object O implements A;
var {public} v : integer;

procedure {public} P implements A.P;
begin
Pi;  (* here I wont to call the implementation A's P *)
v := 2;
end P;

procedure {public} P2 implements A.P2;
begin
writeln("I am O.P2");
end P2;

end O.



module Test;
import O;
var
o : O;
begin
o.P;
writeln("i = ", o.i:0, "  v = ", o.v:0);
readln
end Test. 

The resut is:
  I am A.P2
  i = 5  v = 2

2. Why self.P2 doesn't call the override O.P2, but the local context A.P2? Is just a bug? Is that the behavior I have to expect from self.P2?

Thank you,
Dan
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!