blob: 61a3f42bb322edc29c2d04ffd3b6a8f87f60bf6e (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
{ %opt=-gh }
program RefCountBug;
{$ifdef fpc}
//{$mode objfpc}{$H+}
{$mode delphi}
{$endif}
{$ifdef mswindows}
{$apptype console}
{$endif}
uses
Classes,
SysUtils;
type
ITest = interface
function SomeMethod(): ITest;
function GetValue(): AnsiString;
end;
TTest = class(TInterfacedObject, ITest)
private
fValue: AnsiString;
public
constructor Create(Value: AnsiString);
destructor Destroy(); override;
function SomeMethod(): ITest;
function GetValue(): AnsiString;
end;
constructor TTest.Create(Value: AnsiString);
begin
inherited Create();
fValue := Value;
Writeln('TTest.Create('+Value+')');
end;
destructor TTest.Destroy();
begin
Writeln('TTest.Destroy('+fValue+')');
inherited;
end;
function TTest.SomeMethod(): ITest;
begin
if (FRefCount <> 1) then
halt(1);
Writeln('SomeMethod: ' + fValue, ' ', FRefCount);
Result := TTest.Create(fValue + ',MethodCall');
end;
function TTest.GetValue(): AnsiString;
begin
Result := fValue;
end;
var
t: ITest;
begin
HaltOnNotReleased := true;
t := TTest.Create('Create');
Writeln('Result: ' + t.SomeMethod().SomeMethod().GetValue);
end.
|