[fpc-devel] Re: RFC: Delphi style class helpers
    Sven Barth 
    pascaldragon at googlemail.com
       
    Fri Jan  7 10:30:31 CET 2011
    
    
  
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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: tchlp35.pp
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20110107/5d4ba6b7/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: uchlp35.pp
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20110107/5d4ba6b7/attachment-0001.ksh>
    
    
More information about the fpc-devel
mailing list