Solved

SELF parameter

Posted on 2004-04-12
6
365 Views
Last Modified: 2010-04-05
Hi all,
I have a simple question.

I have to form A and B.
Form B inherits from Form A

In FORM A-

procedure CallP (formName :TForm); virtual; abstract;
procedure example;
.
.
procedure TFormA.example (tobject example);
begin
   FormB.CallP(SELF);
end;
 
-------------------------------
Form B
procedure CallP (formName :TForm); override

procedure TFormB.CallP (formName :TForm);
begin
  inherited;
 
end;


My question is what does the SELF in this sentence -formB.call(self)- means?
does it means TFormA it self and it passes the parameter (TFormA) to formB.CallP
OR
it passes to as SELF to form B and when Form B calles it it calls as itself (TformB)?

I'm confused about the self statement

Thank you

Ian
0
Comment
Question by:AgeOfWars
[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
6 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 10805459
Self refers to the object within whose scope the procedure resides. Therefore the call FormB.CallP(SELF) within TFormA.example refers to the object of type TFormA. Within the TFormB context, it refers to the TFormB object.
0
 
LVL 9

Expert Comment

by:Cayce
ID: 10805665
The Self parameter means you're passing a reference to the current class instantation (current object).

That is, the TFormB.CallP method expects a TForm parameter, and you're sending the reference of the current instation of TFormA (which should be FormA).

Self is the reference to the current object.

0
 

Author Comment

by:AgeOfWars
ID: 10805714
Hi Cayce and Sftweng

both of your answers are not the same? maybe it is but i'm still not very sure.

Cayce, what you mean is, when TformB.callP (formName :TForm); is called in formB. It is to said that the sentence will be written as TformB.callP (self);  ? Doesn't this refer to formB it self as what Sftweng was saying??

Correct me if i'm wrong. Thanks
ian
0
Industry Leaders: 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!

 
LVL 9

Accepted Solution

by:
Cayce earned 100 total points
ID: 10805797
Specifically to your program:

procedure TFormA.example (tobject example);
begin
   FormB.CallP(SELF);
end;

I'm pretty sure that Self equals FormA, which would be the current instance of TFormA.

Self is the current instance of the class you're in. In this case you're writing code on the TFormA class. So self is a reference to a TFormA object.

0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10811198

   Self, Application are "transparent" variables.

  procedure TFormA.example (....);
  begin
    FormB.CallP(SELF);  // here Self reffers to FormA, because you are in the Scope of FormA
  end;

  In addition, if you have ActiveX form in DLL and compile stand alone - Application is the DLL file, but if you have EXE application the use this form, then Application variable is the EXE file ...
0
 

Author Comment

by:AgeOfWars
ID: 10812291
Thanks Cayce for you answser
0

Featured Post

Technology Partners: 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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

690 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