Delphi - Generic Validation Type if Created

I have the following class definition

  TBase<T> = class
  public
    class var Inst: T;
    class function GetClone: T;
  end;

      

And I want to check if the var Inst is assigned.

class function TBase<T>.GetClone: T;
begin
 if TBase<T>.Inst = nil then //- error here. Trying with Assigned(TBase<T>.Inst) is also nor recognized.
    TBase<T>.Inst := TBase<T>.Create;
end;

      

How can I check if my class variable is assigned?

+3


source to share


1 answer


You need to limit the general parameter to check nil

. For example:

TBase<T: class> = class //...

      



This way T

must be TObject

or any descendant, so you can check nil

.

Without limitation, it T

can be integer

or any other value type that does not support nil

.

+3


source







All Articles