class-helpers

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

那年仲夏 提交于 2019-12-30 06:03:48
问题 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? 回答1: At most one helper can active at any one point in your code. The documentation says this: You can define and associate multiple helpers

How to encapsulate different classes within one class mantaining their unique methods? (multiple inheritance in delphi?)

人走茶凉 提交于 2019-12-23 13:15:27
问题 I'm currently rewriting a free educational digital circuit simulator to add inertiality to its features. My problem is how to dispatch events to original classes adding a pre-elaboration to them. I have something like this: TC1 = class ID: integer; Connections : array [integer] of Pin; function Func1; virtual; function FuncN; end; TC2-1 = class (TC1) function Func1; override; function My1Func(); end; TC2-n = class (TC1) function Func1; override; function MyNFunc(); end; TContainer = class C1

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

两盒软妹~` 提交于 2019-12-17 15:48:08
问题 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

How can access the value of a class var using the address of the class and a offset to the variable?

亡梦爱人 提交于 2019-12-12 09:43:52
问题 I Need to access a strict private class var value of a class using his instance and a offset to the variable. so far tried this , check this sample class type TFoo=class strict private class var Foo: Integer; public constructor Create; end; constructor TFoo.Create; begin inherited; Foo:=666; end; //this function works only if I declare the foo var as //strict private var Foo: Integer; function GetFooValue(const AClass: TFoo): Integer; begin Result := PInteger(PByte(AClass) + 4)^ end; As you

How to access the private method TStreamReader.FillBuffer in Delphi 10.1 Berlin? [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-11 08:17:35
问题 This question already has answers here : How to access private methods without helpers? (6 answers) Closed 3 years ago . How to access the private method TStreamReader.FillBuffer in Delphi 10.1 Berlin, we did it with a class helper before 10.1 - but the proposed solution does not work: uses System.Rtti; procedure TForm1.FormCreate(Sender: TObject); begin Assert(Assigned(TRttiContext.Create.GetType(TStreamReader).GetMethod('FillBuffer')), 'Failed'); end; it fails just because GetMethod returns

Find all Class Helpers in Delphi at runtime using RTTI?

五迷三道 提交于 2019-12-07 05:42:18
问题 Does the extended RTTI in Delphi 2010 offer a way to list defined Class and Record Helpers at run time? As far as I know Delphi does not show a hint or warning when more than one class helper is defined for a class, class helper detection might be a helpful routine in 'quality assurance'. p.s. of course I know I should never ever use third party components or libraries without source code, which would make it easy to grep class helpers. 回答1: Since class helpers only apply to a class based on

How can access the value of a class var using the address of the class and a offset to the variable?

混江龙づ霸主 提交于 2019-12-05 14:43:50
I Need to access a strict private class var value of a class using his instance and a offset to the variable. so far tried this , check this sample class type TFoo=class strict private class var Foo: Integer; public constructor Create; end; constructor TFoo.Create; begin inherited; Foo:=666; end; //this function works only if I declare the foo var as //strict private var Foo: Integer; function GetFooValue(const AClass: TFoo): Integer; begin Result := PInteger(PByte(AClass) + 4)^ end; As you see the function GetFooValue works only when the foo variable is not declarated like a class var. The

Find all Class Helpers in Delphi at runtime using RTTI?

↘锁芯ラ 提交于 2019-12-05 09:56:11
Does the extended RTTI in Delphi 2010 offer a way to list defined Class and Record Helpers at run time? As far as I know Delphi does not show a hint or warning when more than one class helper is defined for a class, class helper detection might be a helpful routine in 'quality assurance'. p.s. of course I know I should never ever use third party components or libraries without source code, which would make it easy to grep class helpers. Since class helpers only apply to a class based on what helper is "closest" in scope, a class simply cannot know that a helper exists. For example, you can

Should Class Helpers be used in developing new code?

北城以北 提交于 2019-12-04 18:21:32
问题 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

Class Helper for generic class?

倖福魔咒の 提交于 2019-12-03 12:53:06
问题 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; 回答1: 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