[Overview][Resource strings][Constants][Types][Classes][Procedures and functions][Index] |
The class that owns this object
Source position: tiObject.pas line 427
public property TtiObject.Owner : TtiObject |
The class that owns this object. If I am owned by a TtiObjectList, then my owner is the object responsible for my destruction.
It some cases it is very useful to set Owner to something different. This is often done to make code more readable. Lets take a quick look at a very basic address book example where we have a TClient that has a PhoneNumberList property. The list contains TPhoneNumber instances. We could then write code like the following - using the Owner property of the PhoneNumber to get to the Client that phone number belongs to.
lClient := lPhonenumber.Owner as TClient;
Now as we mentioned, a TPhoneNumber lives inside a TPhoneNumberList, yet Phonenumber.Owner doesn't return the TPhoneNumberList. That is because when you create the TPhoneNumberList instance, you can tell it who is the acting Owner. TClient's constructor does that.
constructor TClient.Create; begin inherited; FPhoneNumbers := TPhoneNumbers.Create; FPhoneNumbers.Owner := Self; // **** Changing Owner here **** end;
This is for convenience and makes the code easier to read, otherwise you would have to type "lPhoneNumber.Owner.Owner as TClient" which just looks ugly. :)
|
Base class for list objects |
|
|
The parent of this object |