Solved

object inside object

Posted on 1999-01-03
1
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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