tmshlp3.pp 538 B

1234567891011121314151617181920212223242526272829303132
  1. {$mode objfpc}
  2. {$modeswitch typehelpers}
  3. {$modeswitch multihelpers}
  4. program tmshlp3;
  5. type
  6. TStringHelper1 = type helper for String
  7. function Length: integer;
  8. end;
  9. function TStringHelper1.Length: integer;
  10. begin
  11. result := System.Length(self);
  12. end;
  13. type
  14. TStringHelper2 = type helper for string
  15. function LengthSquared: integer;
  16. end;
  17. function TStringHelper2.LengthSquared: integer;
  18. begin
  19. result := self.Length * self.Length;
  20. end;
  21. var
  22. s: string = 'abcd';
  23. begin
  24. if (s.Length <> 4) or (s.LengthSquared <> 16 ) then
  25. Halt(1);
  26. end.