Methods are very similar to procedures and functions. The real difference is that methods have an implicit parameter, which is
a reference to the current object.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Within a method you can refer to this parameter—the current object—using the Self keyword. This extra hidden parameter is needed when you create several objects of the same class, so that each time you apply a method to one of the objects, the method will operate only on its own data and not affect sibling objects.
For example, in the SetValue method of the TDate class, listed earlier, we simply use Month, Year, and Day to refer to the fields of the current object, something you might express as
Self.Month := m;
Self.Day := d;
This is actually how the Delphi compiler translates the code, not how you are supposed to write it. The Self keyword is a fundamental language construct used by the compiler, but at times it is used by programmers to resolve name conflicts and to make tricky code more readable.
NOTE The C++ and Java languages have a similar feature based on the keyword this.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button2Click(Sender:TObject);
var
B1,B2:TButton;
begin
B1:=TButton.Create(self);
B2:=TButton.Create(B1);//B1为B2的宿主(Owner)
B2.Free;
B1.Free;
end;