相关疑难解决方法(0)

为什么在我的Delphi对象上没有调用_AddRef和_Release?

我真的很困惑.

// initial class
type
    TTestClass = 
        class( TInterfacedObject)
        end;

{...}

// test procedure
procedure testMF();
var c1, c2 : TTestClass;
begin
    c1 := TTestClass.Create(); // create, addref
    c2 := c1; // addref

    c1 := nil; // refcount - 1

    MessageBox( 0, pchar( inttostr( c2.refcount)), '', 0); // just to see the value
end;
Run Code Online (Sandbox Code Playgroud)

它应该显示1,但它显示0.无论我们将执行多少分配,值都不会改变!为什么不?

delphi interface reference-counting

2
推荐指数
1
解决办法
1471
查看次数

标签 统计

delphi ×1

interface ×1

reference-counting ×1