[fpc-devel] Allow record helper inheritance in Delphi mode
    Ondrej Pokorny 
    lazarus at kluug.net
       
    Tue Aug 29 17:38:45 CEST 2017
    
    
  
There is a difference between FPC 3.0.0 and current trunk (without my 
patch) regarding {$modeswitch typehelpers} and "TXYZHelper = type helper 
for TXYZ".
In 3.0.0 it is obvious - it can be used only for primitive types.
In trunk you can use type helper for everything (with {$modeswitch 
typehelpers}) - primitive types, record, classes and interfaces (btw. 
thanks for the interfaces - you should announce it loud :) ).
Example code:
program DelphiHelpers;
{$mode objfpc}
{$modeswitch advancedrecords+}
{$modeswitch typehelpers+}
type
   TRec = record
   public
     function A: string;
   end;
   TRecHelper = type helper for TRec
   public
     function AB: string;
   end;
   TObjectHelper = type helper for TObject
   public
   end;
{ TRecHelper }
function TRecHelper.AB: string;
begin
   Result := inherited A + 'b';
end;
{ TRec }
function TRec.A: string;
begin
   Result := 'a';
end;
var
   T: TRec;
begin
   if T.AB <> 'ab' then
     Halt(1);
   Writeln('ok');
end.
-> It compiles fine in trunk but does not compile in 3.0.0.
So yes, your description of {$modeswitch typehelpers} makes sense for 
3.0.0 but not for trunk any more. So what is your intention - 3.0.0 
behavior or trunk behavior?
Ondrej
    
    
More information about the fpc-devel
mailing list