Solved

object inside object

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

13 Experts available now in Live!

Get 1:1 Help Now