Hi! When I check the declaration of TObject in "System" unit, I found these code:
[code]
TObject = class
constructor Create;
procedure Free;
class function InitInstance(Instance: Pointer): TObject;
[/code]
There is a keyword "class" before the declaration of function "InitInstance", can you tell me what does it mean or which part of help file shall I read?
Thank you!
Comments
Documentation tells:
"A class method can be called through a class reference or an object reference. When it is called through and object reference, the class of the object becomes the value of Self."
However, I still don't know what is the difference between a Class Method and other methods.
Also, "the class of the object becomes the value of Self" => "class becomes value of Self", here "Self" is a variable. I don't understand why class can become a variable.
Thank you!
this is the core of delphi, the class method is build in into the compiler itselve, not available for us.
when calling it, it runs some code to register the class for windows wheter it is an object class or other, delphi knows what to do with it.
so TObject is the first class object created with the classmethod and you should start from there, or if you are programming a compiler then you should start to learn ASM ) (wich you probebly allready have)
However, the thing currently I'm concerning is:
what is the difference between "InitInstance" and other method defined without "class" in front of it.
[code]
TObject = class
constructor Create;
procedure Free;
class function InitInstance(Instance: Pointer): TObject;
[/code]
Thank you!
: this is the core of delphi, the class method is build in into the compiler itselve, not available for us.
:
: when calling it, it runs some code to register the class for windows wheter it is an object class or other, delphi knows what to do with it.
:
: so TObject is the first class object created with the classmethod and you should start from there, or if you are programming a compiler then you should start to learn ASM ) (wich you probebly allready have)
:
:
:
A class method is not something for the core of Delphi, but a method, which can also be applied to the class definition itself. Example:
[code]
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Caption := TButton.ClassName; // a class function
end;
[/code]
This code will show the name of the class itself, not an instance of the object. Since ClassName() is a class method (see help file), this is a valid code, while the following code will generate an error:
[code]
procedure TForm1.Button1Click(Sender: TObject);
begin
TButton.Click; // not a class method
end;
[/code]
The Click() method cannot be called from the class definition of a TButton, but only from an TButton instance.