Solved

SELF parameter

Posted on 2004-04-12
6
361 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 67
Print Graphic and Text to Epson TM-T88v 12 538
shape, triangle, dbctrlgrid 3 42
Connect to SQL 2008 r2 server over the Internet 4 74
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…

738 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