Delphi - generic type check if is created -
i have following class definition
tbase<t> = class public class var inst: t; class function getclone: t; end; and want check if class var inst assigned.
class function tbase<t>.getclone: t; begin if tbase<t>.inst = nil //- error here. trying assigned(tbase<t>.inst) nor recognized. tbase<t>.inst := tbase<t>.create; end; how can check if class variable assigned?
you need constraint generic parameter in order check nil. example:
tbase<t: class> = class //... that way t must tobject or descendant of it, can check nil.
without constraint t can integer or other value type doesn't support nil.
Comments
Post a Comment