havrlisan 24 Posted December 9, 2022 (edited) Is it possible to use attributes in these scenarios: // First scenario [MyAttr] TMyGuid = TGuid; // Second scenario [MyAttr] TMyDT = TDateTime; I found this article that says it's not possible to use attributes on aliases of simple ordinal types, only on actual sub-types by using the type keyword. I'm asking this because I believe declaring my TMyGuid type as a sub-type for TGuid rather than an alias will break a lot of my code. Is there really no way to use attributes on aliases like this? Update: I realized that changing my declaration to TMyGuid = type TGuid; will only cause the loss of TGuidHelper. Unfortunately, class helper inheritance is still not available so I will have to rewrite it for my sub-type. Edited December 9, 2022 by havrlisan update Share this post Link to post
programmerdelphi2k 237 Posted December 9, 2022 (edited) type TMyGUID = TGUID; // your "alias" that way TMyHlpToTGUID = record helper for TGUID function MyFunc: string; end; TMyHlpToTMyGUID = record helper for TMyGUID function MyMyFunc: string; end; procedure TForm1.Button1Click(Sender: TObject); var x: TMyGUID; begin x := TMyGUID.Create('123...'); x.MyMyFunc; // MyMyFunc "hide" MyFunc now... helper to same type-base TGUID! end; { TMyHlpToTGUID } function TMyHlpToTGUID.MyFunc: string; begin result := 'Hello'; end; { TMyHlpToTMyGUID } function TMyHlpToTMyGUID.MyMyFunc: string; begin result := 'World'; end; end. as "TMyGUID" is, in fact, "TGUID" (yet), then your attributes should works in "TGUID" not in "TMyGUID" as showed in your "blog post", the real type is "TGUID", then, you needs works with it, not "TMyGUID" Edited December 9, 2022 by programmerdelphi2k Share this post Link to post
havrlisan 24 Posted December 12, 2022 On 12/9/2022 at 2:11 PM, programmerdelphi2k said: type TMyGUID = TGUID; // your "alias" that way TMyHlpToTGUID = record helper for TGUID function MyFunc: string; end; TMyHlpToTMyGUID = record helper for TMyGUID function MyMyFunc: string; end; procedure TForm1.Button1Click(Sender: TObject); var x: TMyGUID; begin x := TMyGUID.Create('123...'); x.MyMyFunc; // MyMyFunc "hide" MyFunc now... helper to same type-base TGUID! end; { TMyHlpToTGUID } function TMyHlpToTGUID.MyFunc: string; begin result := 'Hello'; end; { TMyHlpToTMyGUID } function TMyHlpToTMyGUID.MyMyFunc: string; begin result := 'World'; end; end. as "TMyGUID" is, in fact, "TGUID" (yet), then your attributes should works in "TGUID" not in "TMyGUID" as showed in your "blog post", the real type is "TGUID", then, you needs works with it, not "TMyGUID" I see, so it is not possible to declare attributes for aliases. Thanks for your answer. Share this post Link to post