Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-09

OO problem

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

James Mills
sdebug.pas(41,12) Error: methods can be only in other methods called
direct with type identifier of the class
sdebug.pas(41,12) Error: Illegal expression
sdebug.pas(41,12) Fatal: Syntax error, ; expected but identifier START
found

Can someone help me out here, technically I should be able to inherit the parents method, start?

cheers
James

Sources are attached.

Reply by email

Yet Another Geek
Show quoted text 8 lines
> In java you can do this... > Super.start(); > Can this be done in FPC ? Do you mean heritage? Like this: procedure B.start; begin // inherited A; { <- This is wrong! }
inherited start; { <- Should be this.}
end;

You can also typecast the implicit "self" parameter to inherit from any class in the family tree:

program inherit;
{$MODE OBJFPC}
// Grandparent:
type tObjA = class
  procedure start;
end;
// Parent:
type tObjB = class (tObjA)
  procedure start;
end;
// Child:
type tObjC = class (tObjB)
  procedure start;
end;
// tObjA implements a "start" method...
procedure tObjA.start;
begin
  WriteLn('Hello');
end;
// tObjB overrides the parent's method...
procedure tObjB.start;
begin
  WriteLn('World');
end;
// C can inherit from A, B, or both...
procedure tObjC.start;
begin
  tObjA(self).start; // cast to grandparent
  tObjB(self).start;  // cast to parent
end;
// Show me!
var
  MyC:tObjC;
begin
  MyC:=tObjC.Create;
  MyC.start;
  MyC.Free;
end.

__________________________________________________ Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

Reply by email