class-helpers

Should Class Helpers be used in developing new code?

混江龙づ霸主 提交于 2019-12-03 12:06:14
Delphi 8 introduced Class Helpers for the purposes of mapping the VCL/RTL to the .NET object hierarchy. They allow injecting methods into an existing class without overriding the the class or modifying the original. Later versions of Delphi found class helpers improved and they were ported to Win32. In the help it says "they should not be viewed as a design tool to be used when developing new code." Class Helpers violate traditional OOP, but I don't think that makes them a bad thing. Is this warning warranted? Should class helpers be used when developing new code? Do you use them when

Class Helper for generic class?

陌路散爱 提交于 2019-12-03 03:15:03
I'm using Delphi 2009. Is it possible to write a class helper for a generic class, i.e. for TQueue . The obvious TQueueHelper <T> = class helper of TQueue <T> ... end; does not work, nor does TQueueHelper = class helper of TQueue ... end; As documented in the Delphi help, class helpers are not designed for general purpose use and they are incorrectly perceived as having a number of limitations or even bugs as a result. nevertheless there is a perception - incorrect and dangerous in my view - that these are a legitimate tool in the general purpose "toolkit". I have blogged about why this is

Is it possible to use two record helpers for the string type?

核能气质少年 提交于 2019-11-30 18:46:15
I created this helper in order to add some more functions to the string type: type AStringHelper = record helper for string function Invert: string; overload; function InvertMe: string; overload; end; But when I use it in my code, the TStringHelper in System.StrUtils "gets out" and I can't use it's functions. Is it possible to both of them to coexist? At most one helper can active at any one point in your code. The documentation says this: You can define and associate multiple helpers with a single type. However, only zero or one helper applies in any specific location in source code. The

How to access a private field from a class helper in Delphi 10.1 Berlin?

梦想与她 提交于 2019-11-28 10:05:55
I would like to use Gabriel Corneanu's jpegex , a class helper for jpeg.TJPEGImage. Reading this and this I've learned that beyond Delphi Seattle you cannot access private fields anymore like jpegex does (FData in the example below). Poking around with the VMT like David Heffernan proposed is far beyond me. Is there any easier way to get this done? type // helper to access TJPEGData fields TJPEGDataHelper = class helper for TJPEGData function Data: TCustomMemoryStream; inline; procedure SetData(D: TCustomMemoryStream); procedure SetSize(W,H: integer); end; // TJPEGDataHelper function

Access a strict protected property of a Delphi class?

拥有回忆 提交于 2019-11-27 21:20:20
I need to access a strict protected property , because I need to create a validation (based in the value of this property) to avoid a bug. (I don't have the source code of the third party class which has this property) only I have the definition of the class (interface) and the dcu (so I can't change the property visibility). The question is Exist a way to access a strict protected property? (I really read the Hallvard Vassbotn Blog , but I don't find anthing about this particular topic.) This class helper example compiles fine : type TMyOrgClass = class strict private FMyPrivateProp: Integer;

How do I use class helpers to access strict private members of a class?

自作多情 提交于 2019-11-27 20:04:20
This is a follow-up question to: How to hide a protected procedure of an object? (I'm a bit fuzzy on the whole class helper concept) Suppose I have an class like: type TShy = class(TObject) strict private procedure TopSecret; private procedure DirtyLaundry; protected procedure ResistantToChange; end; I know I can access the private method if I have the source code by adding a descendent class in the same unit. I have 2 questions: - How do I employ a class helper to access the strict private member? - Can I use a class helper in a separate unit to access (strict) private members? Remy Lebeau Up

How to access a private field from a class helper in Delphi 10.1 Berlin?

﹥>﹥吖頭↗ 提交于 2019-11-27 03:23:14
问题 I would like to use Gabriel Corneanu's jpegex, a class helper for jpeg.TJPEGImage. Reading this and this I've learned that beyond Delphi Seattle you cannot access private fields anymore like jpegex does (FData in the example below). Poking around with the VMT like David Heffernan proposed is far beyond me. Is there any easier way to get this done? type // helper to access TJPEGData fields TJPEGDataHelper = class helper for TJPEGData function Data: TCustomMemoryStream; inline; procedure

Access a strict protected property of a Delphi class?

白昼怎懂夜的黑 提交于 2019-11-26 23:03:40
问题 I need to access a strict protected property , because I need to create a validation (based in the value of this property) to avoid a bug. (I don't have the source code of the third party class which has this property) only I have the definition of the class (interface) and the dcu (so I can't change the property visibility). The question is Exist a way to access a strict protected property? (I really read the Hallvard Vassbotn Blog, but I don't find anthing about this particular topic.) 回答1: