Solved

SELF parameter

Posted on 2004-04-12
6
336 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
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

19 Experts available now in Live!

Get 1:1 Help Now