Solved

object inside object

Posted on 1999-01-03
1
214 Views
Last Modified: 2013-11-23
this should be an easy one.

if in an object method declaration I want to create another object to use within that method, what is the best way to do it?  Particularly with respect to the Create method of the created object - do you use 'Self' or 'Nil' or something else?  Exactly what does 'self' mean anyway?  My understanding is that a reference to 'self' within the declaration of an object method is a reference to the object itself, once it is created.  is this true?

eg:

type
  TMyObject = class(TWhatever)
  public
    procedure Execute; override;
  end;

implementation

procedure TMyObject.Execute;
var
  Other : TAnotherObject;
begin
  Other:=TAnotherObject.Create(Self);
  {now do something with Other}
  Other.Free;
end;

thanks,

Ben
0
Comment
Question by:1750
1 Comment
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1354371
SELF will refer in this case to TMyObject so when you pass SELF as the parameter it will replace it with TMyObject.... You use NIL as the Owner when you don't want your object to have an owner and when you want to have an owner you use its name.... In this case when you say Boject.Create(SELF) you tell the Conctructor to set TMyObject as the owner of our new object.,,,

Hope this info helps...

-Viktor
--Ivanov
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Filemaker 14 vs Delphi Embarcadero 7 186
Wininet read php file from internet issue 6 81
Newbie Thread Programming 1 139
Create a path if not exists 7 69
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now