Form.Release + NIL

后端 未结 5 1359
无人及你
无人及你 2021-02-05 21:24

if Form.Release is called after using the form, it will free all related memory but not set the form variable to nil.

if not assigned (Form1) then
  begin
    Ap         


        
5条回答
  •  天命终不由人
    2021-02-05 21:36

    Of you could just always call this:

    procedure FreeOrReleaseAndNil(var Obj);
    var
      Temp: TObject;
    begin
      Temp := TObject(Obj);
      Pointer(Obj) := nil;
      if Temp is TCustomForm then
        TCustomForm(Temp).Release
      else
        Temp.Free;
    end;
    

    Be sure to check the type after casting to a TObject as you can't test the type of Obj. This should be safe since like Free, Release is non-virtual.

提交回复
热议问题