Ugochukwu Mmaduekwe 42 Posted February 19, 2020 Hi, So here is what I want to achieve. I have a class named TA. in class TA, I have a record named TB. is it possible to get the constructed instance of TA as a variable in TB without the use of an external variable that is assigned at the construction of TA of course? type TA = class abstract(TObject) strict private type TB = record private var ClassAInstance: TA; // ========================> is it possible to get the constructed instance of TA in TB so I can assign it to the variable. Block: array [0 .. 7] of Byte; Offset: UInt64; BlockOffset: Int32; function Clone(): TB; procedure Read(const ADestination: TBytes; ADestinationOffset, AOutputLength: UInt64); class function DefaultB(): TB; static; end; Thanks. Share this post Link to post
Lars Fosdal 1791 Posted February 19, 2020 Not sure that I understand the full context, but assuming you have an instance of TB in TA, overriding TA.AfterConstruction would allow you to assign self to that instance of TB? Share this post Link to post
Der schöne Günther 316 Posted February 19, 2020 By itself, TB does not really have much to do with TA. It's just a type definition, it's full type name is TA.TB. Since it's just a type definition and no instance, you could have multiple instances of TB inside your TA instance. You can have TA.TB instances outside of a TA instance. You can have a TA instance with no TA.TB inside at all. 1 Share this post Link to post
Attila Kovacs 629 Posted February 19, 2020 Not outside, as it's strict private. You could pass TA instances to the method you are using to initialize your record. class function DefaultB(ATA: TA): TB; static; begin Result.ClassAInstance := ATA; end; 1 Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted February 19, 2020 35 minutes ago, Lars Fosdal said: Not sure that I understand the full context, but assuming you have an instance of TB in TA, overriding TA.AfterConstruction would allow you to assign self to that instance of TB? Hmm, That looks like something that could work. will check it out, Thanks. 1 Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted February 19, 2020 13 minutes ago, Attila Kovacs said: Not outside, as it's strict private. You could pass TA instances to the method you are using to initialize your record. class function DefaultB(ATA: TA): TB; static; begin Result.ClassAInstance := ATA; end; Don't know why I didn't think of this in the first place. Thanks a lot. Share this post Link to post