tag:blogger.com,1999:blog-29331675.post2690677538267881449..comments2024-03-05T17:37:00.995+01:00Comments on The Delphi Geek: Creating an Object from an Unconstrained Generic Classgabr42http://www.blogger.com/profile/06903558857617342477noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-29331675.post-69663693742994261322016-11-02T07:18:42.480+01:002016-11-02T07:18:42.480+01:00if in a generic class with an unconstrained type p...if in a generic class with an unconstrained type parameter is initiated without specifying actual type argument ?<br />Anonymoushttps://www.blogger.com/profile/11351525236425825895noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-30029752400198825852011-12-15T11:43:20.108+01:002011-12-15T11:43:20.108+01:00@Sergey, AFAIK overloads don't work here.@Sergey, AFAIK overloads don't work here.gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-44148160025260843512011-12-15T11:32:52.044+01:002011-12-15T11:32:52.044+01:00Sorry,
Use Overloads,
Atomic.Initialize < T:c...Sorry,<br /><br />Use Overloads,<br /><br />Atomic.Initialize < T:class,constructor > <br /> (var storage: T): T;<br /><br />Atomic.Initialize < T: Iunknown > (var storage: T): T;<br /><br />Or<br /><br />Atomic.Initialize < T:class,constructor; W:Iunknown > <br /> (var storage: T): W;<br /><br />cast T to W via getinterface for instance.Sergey Antonov aka oxffffhttps://www.blogger.com/profile/10045102019512764602noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-68570931669725742272011-12-15T11:29:15.502+01:002011-12-15T11:29:15.502+01:00Why do you mix the semantic of types in one operat...Why do you mix the semantic of types in one operation?<br /><br /> - is safe solution for objects.<br /><br />Try to use overload mechanism:<br /><br />Atomic.Initialize(var storage: T): T;<br />Atomic.Initialize(var storage: T): T;<br /><br />Or may be<br /><br />Atomic.Initialize(var storage: T): W;<br />cast t to w.<br /><br />I have only R3 and abap near at hand. :)<br />Delphi at night. :))))Sergey Antonov aka oxffffhttps://www.blogger.com/profile/10045102019512764602noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-80761557138585626282011-12-15T11:21:38.718+01:002011-12-15T11:21:38.718+01:00OK, I have the solution; I'll correct the arti...OK, I have the solution; I'll correct the article. Thanks!gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-48567037637371256072011-12-15T11:00:58.780+01:002011-12-15T11:00:58.780+01:00@Sergey, you are right! Do you have a solution for...@Sergey, you are right! Do you have a solution for that?gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-59030233807364140882011-12-15T10:51:17.152+01:002011-12-15T10:51:17.152+01:00>His solution was to use
>Result := >T(Ge...>His solution was to use<br />>Result := >T(GetTypeData(PTypeInfo(TypeInfo(T)))^.ClassTyp>e.Create);<br /><br />This is an inproper and unsafe solution as you use an Tobject.create (Empty initializer).Sergey Antonov aka oxffffhttps://www.blogger.com/profile/10045102019512764602noreply@blogger.com