Solved

object inside object

Posted on 1999-01-03
1
218 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DBGrid or StringGrid ? 6 105
Drag & Drop... Data from one grid to another 2 42
how to change, disabled button color FMX ? 1 40
Twebbrowser add css to the header 3 29
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…

829 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