拖管记录
DELPHI10.4开始支持 拖管记录。
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TMyRecord = record Value: Integer; class operator Initialize (out Dest: TMyRecord); class operator Finalize(var Dest: TMyRecord); end; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} class operator TMyRecord.Initialize (out Dest: TMyRecord); begin Dest.Value := 10; form1.Memo1.Lines.Add('created' + IntToHex (Integer(Pointer(@Dest)))); end; class operator TMyRecord.Finalize(var Dest: TMyRecord); begin form1.Memo1.Lines.Add('destroyed' + IntToHex (Integer(Pointer(@Dest)))); end; procedure TForm1.Button1Click(Sender: TObject); begin var r: TMyRecord; memo1.Lines.Add(r.Value.ToString); end; end.
测试:
created0019F398
10
destroyed0019F398