summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/test/tstatic2.pp
blob: 956c94d7d250f95034343f3992b9e0c1ae081a98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
program tstatic2;
{$APPTYPE console}
{$ifdef fpc}
  {$mode delphi}{$H+}
{$endif}

type
  TSomeClass = class
  private
    class var
      FSomethingStatic: Integer;
  public
    class procedure SetSomethingStatic(AValue: Integer); static;
    class property SomethingStatic: Integer read FSomethingStatic write SetSomethingStatic;
  end;

  TAnotherClass = class(TSomeClass)
  end;

{ TSomeClass }

class procedure TSomeClass.SetSomethingStatic(AValue: Integer);
begin
  FSomethingStatic := AValue;
  WriteLn('SomethingStatic:', SomethingStatic);
end;

begin
  TSomeClass.SomethingStatic := 4;
  if TSomeClass.SomethingStatic <> 4 then
    halt(1);
  TAnotherClass.SomethingStatic := 10;
  if TSomeClass.SomethingStatic <> 10 then
    halt(2); // outputs 10
end.