Hello again!
In the last few days I've written quite a few tests regarding class
helpers and have come across some interesting cases. I've used Delphi
2007 to compile these tests.
Case 1:
The following code compiles in Delphi
=== source begin ===
program tchlp20;
{$ifdef fpc}
{$mode objfpc}
{$endif}
type
TObjectHelper = class helper for TObject
end;
TSomeRec = record
helper: TObjectHelper;
end;
begin
end.
=== source end ===
This is strange, because every other reference to a class helper (
variable declaration, parameter, parent class) results either in a error
or even in an internal error (haha ^^). Can someone test with a newer
version of Delphi (e.g. XE)?
If a newer Delphi also successfully generates a binary for this, should
I consider this a bug or does someone knew more about this?
Case 2:
The following code compiles as well, which scares me a bit, cause I have
to implement that as well :P
=== source begin ===
program tchlp36;
type
TObjectHelper = class helper for TObject
procedure Test;
end;
TFoo = class
end;
TFooHelper = class helper(TObjectHelper) for TFoo
end;
procedure TObjectHelper.Test;
begin
end;
var
f: TFoo;
begin
f.Test;
end.
=== source end ===
I yet need to test what happens if the extended classes don't inherit
from eachother...
Case 3:
I have attached two sources (tchlp35.pp and uchlp35.pp) for a test
regarding virtual methods in class helpers. This code does not compile
in Delphi 2007, but it might in Delphi XE. So could someone who has
access to a Delphi XE compile those tests and send me the binary, please
(you need to compile the unit first, cause Delphi does not find *.pp
sources)?
At last I have a question regarding compiler development:
Should I use new error messages like "reference to class helper not
allowed here" and so on or should I rely on the messages that are
already there? If the first: what needs to be changed to add a new message?
Regards,
Sven
{ tests virtual methods inside class helpers }
program tchlp35;
type
TObjectHelperB = class helper(TObjectHelperA) for TObject
function VirtualTest: Integer; override;
end;
function TObjectHelperB.VirtualTest: Integer;
begin
Result := 2;
end;
var
o: TObject;
res: Integer;
begin
o := TObject.Create;
res := o.Test;
if res <> 2 then
Halt(1);
end.
unit uchlp35;
{$ifdef fpc}
{$mode objfpc}{$H+}
{$endif}
interface
type
TObjectHelperA = class helper for TObject
function Test: Integer;
function VirtualTest: Integer; virtual;
end;
implementation
function TObjectHelperA.Test: Integer;
begin
Result := VirtualTest;
end;
function TObjectHelperA.VirtualTest: Integer;
begin
Result := 1;
end;
end.
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel