[fpc-devel]Two bugs in OOP including a very important

Ozerski Pavel ozerski at list.ru
Mon Jan 20 15:06:44 CET 2003


Hello all,

There are two bug reports.

1) I found an important and IMHO very unpleasant Delphi incompatibility
in messages handling in classes. Problem description:

in Delphi (I tested D3), if a message handler (with MESSAGE keyword)
has no overriden handler in parent class, using anonymous INHERITED
operator causes calling of DefaultHandler method that handles all
messages which have no specially defined handlers. In FPC 1.0.6
release, this situation causes compilation error. In FPC 1.1 branch
(I tested a relatively fresh snapshot, built at 17.01.03), this
INHERITED is simply ignored in this situation. At result, the same
program compiled by Delphi and by FPC 1.1 can show different
behaviour. This problem can cause fatal problems e.g. by trying to
port to Lazarus Delphi components.

Example:

{$apptype console}
{$ifdef fpc}
 {$mode delphi}
{$endif}

type
 tClassA=class
  procedure DefaultHandler(var Message);override;
 end;

 tClassB=class(tClassA)
  procedure test(var m);message 1;
 end;

 tClassC=class(tClassB)
  procedure test(var m);message 1;
 end;


procedure tClassA.DefaultHandler(var Message);
 begin
  writeln('DDDDDDDDDD');
 end;

procedure tClassB.test(var m);
 begin
  writeln('BBBBBBBBBB');
  inherited;
 end;

procedure tClassC.test(var m);
 begin
  writeln('CCCCCCCCCC');
  inherited;
 end;

var
 C:tObject;
const
 One:longint=1;
begin
 C:=tClassC.Create;
 C.Dispatch(One);
 C.Destroy;
end.

Output (Delphi 3):
CCCCCCCCCC
BBBBBBBBBB
DDDDDDDDDD

Output (FPC 1.1);
CCCCCCCCCC
BBBBBBBBBB

2) Another bug in INHERITED (tested only in 1.1, sorry...):
For some strange reason, anonymous INHERITED requires semicolon
even before END or UNTIL. This is also a Delphi incompatibility.

Sincerely, Pavel V. Ozerski




More information about the fpc-devel mailing list