Link to home
Start Free TrialLog in
Avatar of AgeOfWars
AgeOfWars

asked on

SELF parameter

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
Avatar of sftweng
sftweng

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.
Avatar of Cayce
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.

Avatar of AgeOfWars

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Cayce
Cayce
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

   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 ...
Thanks Cayce for you answser