小编ToK*_*oKa的帖子

class(TInterfacedObject) 在 Delphi 中是否需要析构函数?

我在这种Destroy()从未被调用的情况下运行。

unit Unit2;

interface

type

// Interface
ITest = Interface(IInterface)
 function IsTrue() : Boolean;
end;

TmyClass = class(TInterfacedObject, ITest)
  public
    // Interface implementation
    function IsTrue() : Boolean;

    constructor Create();
    destructor Destroy(); override;
end;

implementation

constructor TmyClass.Create();
begin
  inherited Create();
end;

destructor TmyClass.Destroy();
begin
  inherited Destroy();
end;

published
  // Property
  property IsItTrue: Boolean read IsTrue;
end.
Run Code Online (Sandbox Code Playgroud)

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, 
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, 
  Vcl.Dialogs, Vcl.StdCtrls, unit2;

type
  TForm1 = class(TForm)
  Button1: TButton;
  procedure FormCreate(Sender: …
Run Code Online (Sandbox Code Playgroud)

delphi tinterfacedobject destroy

0
推荐指数
1
解决办法
592
查看次数

标签 统计

delphi ×1

destroy ×1

tinterfacedobject ×1