mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-12 23:49:45 +02:00
32 lines
538 B
ObjectPascal
32 lines
538 B
ObjectPascal
{$mode objfpc}
|
|
{$modeswitch typehelpers}
|
|
{$modeswitch multihelpers}
|
|
|
|
program tmshlp3;
|
|
|
|
type
|
|
TStringHelper1 = type helper for String
|
|
function Length: integer;
|
|
end;
|
|
|
|
function TStringHelper1.Length: integer;
|
|
begin
|
|
result := System.Length(self);
|
|
end;
|
|
|
|
type
|
|
TStringHelper2 = type helper for string
|
|
function LengthSquared: integer;
|
|
end;
|
|
|
|
function TStringHelper2.LengthSquared: integer;
|
|
begin
|
|
result := self.Length * self.Length;
|
|
end;
|
|
|
|
var
|
|
s: string = 'abcd';
|
|
begin
|
|
if (s.Length <> 4) or (s.LengthSquared <> 16 ) then
|
|
Halt(1);
|
|
end. |