[fpc-devel] Allow record helper inheritance in Delphi mode
Ondrej Pokorny
lazarus at kluug.net
Tue Aug 29 12:44:01 CEST 2017
On 29.08.2017 11:48, Sven Barth via fpc-devel wrote:
> The idea is okay as well, but I'd name it RecordHelperInheritance,
> cause if we'd allow "type helper" in mode Delphi (as Maciej asks) then
> those would support inheritance by default as they aren't Delphi
> compatible as a whole anyway.
Actually, IMO {$modeswitch typehelpers} should be supported in delphi
mode as well - just like {$modeswitch advancedrecords} is. Some code to
test:
program Project1;
{$mode delphi}
{$modeswitch typehelpers+} // it doesn't allow "TStringHelper = type
helper for AnsiString"
{$modeswitch advancedrecords-} // it doesn't disable record helper for TRec
type
TRec = record
A, B: Integer;
end;
TRecHelper = record helper for TRec
public
end;
TStringHelper = type helper for AnsiString
public
end;
begin
end.
Furthermore the record helper Delphi syntax is supported in ObjFPC mode
- even with inheritance [!]:
program Project1;
{$mode objfpc}
{$modeswitch typehelpers+}
{$modeswitch advancedrecords}
type
TRec = record
A, B: Integer;
end;
TRecHelper = record helper for TRec
public
end;
TStringHelper = record helper for AnsiString
public
function R: string;
end;
TStringHelper2 = record helper(TStringHelper) for AnsiString
public
function R2: string;
end;
function TStringHelper2.R2: string;
begin
Result := 'R2';
end;
function TStringHelper.R: string;
begin
Result := 'R';
end;
var
S: AnsiString;
begin
Writeln(S.R2);
end.
So, yes. There are inconsistencies that should be fixed:
1.) Support {$modeswitch typehelpers +/-} in delphi mode.
2.) Add a new modeswitch "RecordHelperInheritance" to enable/disable
record helper inheritance in all modes.
Ondrej
More information about the fpc-devel
mailing list