[fpc-pascal] Check In Interface Type Helpers

Anthony Walter sysrpl at gmail.com
Wed Aug 23 16:07:39 CEST 2017


Here is another example:

type
  TDay = (Monday = 0, Tuesday, Wednesday, Thursday, Friday, Saturday,
Sunday);

  TDayHelper = record helper for TDay
    function AsByte: Byte;
    function ToString: string;
  end;

function TDayHelper.AsByte: Byte;
begin
  Result := Ord(Self);
end;

function TDayHelper.ToString: string;
begin
  case Self of
    Monday: Result := 'Monday';
    Tuesday: Result := 'Tuesday';
    Wednesday: Result := 'Wednesday';
    Thursday: Result := 'Thursday';
    Friday: Result := 'Friday';
    Saturday: Result := 'Saturday';
    Sunday: Result := 'Sunday';
  end;
end;

And you can have code like this:

var
  Day: TDay;
  S: string;
begin
  Day := TDay.Monday;
  S := Day.ToString.ToLower;
  WriteLn(S);
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170823/c0888f73/attachment.html>


More information about the fpc-pascal mailing list